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
# File lib/buby/extends/http_request_response.rb, line 92 def self.implanted? ; @implanted; end
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
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
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
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
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
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
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