module Buby::HttpRequestResponseHelper

Public Class Methods

implant(base) click to toggle source

one-shot method to implant ourselves onto a target object’s class interface in ruby. All later instances will also get ‘us’ for free!

# File lib/buby/extends/http_request_response.rb, line 85
def self.implant(base)
  return if @implanted
  base.class.instance_eval { include(HttpRequestResponseHelper) }
  @implanted = true
end
implanted?() click to toggle source
# File lib/buby/extends/http_request_response.rb, line 92
def self.implanted? ; @implanted; end

Public Instance Methods

req_body() click to toggle source
Alias for: request_body
req_headers() click to toggle source
Alias for: request_headers
req_str() click to toggle source
Alias for: request_str
request_body() click to toggle source

Returns the request message body or an empty string if there is none.

# File lib/buby/extends/http_request_response.rb, line 71
def request_body
  (@req_split ||= req_str.split(%r\r?\n\r?\n/, 2))[1]
end
Also aliased as: req_body
request_headers() click to toggle source

Returns a split array of headers. Example:

[
  ["GET / HTTP/1.1"],
  ["Host", "www.example.org"],
  ["User-Agent", "Mozilla/5.0 (..."],
  ...
]
# File lib/buby/extends/http_request_response.rb, line 62
def request_headers
  if headers=(@req_split ||= req_str.split(%r\r?\n\r?\n/, 2))[0]
    @req_headers ||= headers.split(%r\r?\n/).map {|h| h.split(%r\s*:\s*/,2)}
  end
end
Also aliased as: req_headers
request_str() click to toggle source

Returns the full request as a Ruby String - returns an empty string if request is nil.

# File lib/buby/extends/http_request_response.rb, line 48
def request_str
  return request().nil? ? "" : ::String.from_java_bytes(request())
end
Also aliased as: request_string, req_str
request_string() click to toggle source
Alias for: request_str
response_body() click to toggle source

Returns the message body of the response, minus headers

# File lib/buby/extends/http_request_response.rb, line 40
def response_body
  (@rsp_split ||= rsp_str.split(%r\r?\n\r?\n/, 2))[1]
end
Also aliased as: rsp_body
response_headers() click to toggle source

returns an array of response headers split into header name and value. For example:

[ 
  ["HTTP/1.1 301 Moved Permanently"],
  ["Server", "Apache/1.3.41 ..."],
  ...
]
# File lib/buby/extends/http_request_response.rb, line 32
def response_headers
  if headers=(@rsp_split ||= rsp_str.split(%r\r?\n\r?\n/, 2))[0]
    @rsp_headers ||= headers.split(%r\r?\n/).map {|h| h.split(%r\s*:\s*/,2)}
  end
end
Also aliased as: rsp_headers
response_str() click to toggle source

returns the response as a Ruby String object - returns an empty string if response is nil.

# File lib/buby/extends/http_request_response.rb, line 18
def response_str
  return response().nil? ? "" : ::String.from_java_bytes(response())
end
Also aliased as: response_string, rsp_str
response_string() click to toggle source
Alias for: response_str
rsp_body() click to toggle source
Alias for: response_body
rsp_headers() click to toggle source
Alias for: response_headers
rsp_str() click to toggle source
Alias for: response_str
uri() click to toggle source

Returns a Ruby URI object derived from the java.net.URL object

# File lib/buby/extends/http_request_response.rb, line 78
def uri
  @uri ||= URI.parse url.to_s if not url.nil?
end