Module: Buby::HttpRequestResponseHelper Deprecated
- Defined in:
- lib/buby/implants/http_request_response.rb
Overview
This will change to the new Buby::Implants style in the next release. The interface methods will be overwritten to be Ruby-like themselves. If the standard Java implententation is still desired, use the __method
version (e.g. #__response
or #__request
).
Class Method Summary collapse
-
.implant(base) ⇒ Object
one-shot method to implant ourselves onto a target object’s class interface in ruby.
- .implanted? ⇒ Boolean
Instance Method Summary collapse
-
#request_body ⇒ Object
(also: #req_body)
Returns the request message body or an empty string if there is none.
-
#request_headers ⇒ Object
(also: #req_headers)
Returns a split array of headers.
- #request_str ⇒ Object (also: #request_string, #req_str) deprecated Deprecated.
-
#response_body ⇒ Object
(also: #rsp_body)
Returns the message body of the response, minus headers.
-
#response_headers ⇒ Object
(also: #rsp_headers)
returns an array of response headers split into header name and value.
- #response_str ⇒ Object (also: #response_string, #rsp_str) deprecated Deprecated.
-
#uri ⇒ Object
Returns a Ruby URI object derived from the java.net.URL object.
Class Method Details
.implant(base) ⇒ Object
one-shot method to implant ourselves onto a target object’s class interface in ruby. All later instances will also get ‘us’ for free!
92 93 94 95 96 |
# File 'lib/buby/implants/http_request_response.rb', line 92 def self.implant(base) return if @implanted base.class.instance_eval { include(HttpRequestResponseHelper) } @implanted = true end |
.implanted? ⇒ Boolean
99 |
# File 'lib/buby/implants/http_request_response.rb', line 99 def self.implanted? ; @implanted; end |
Instance Method Details
#request_body ⇒ Object Also known as: req_body
Returns the request message body or an empty string if there is none.
78 79 80 |
# File 'lib/buby/implants/http_request_response.rb', line 78 def request_body (@req_split ||= req_str.split(/\r?\n\r?\n/, 2))[1] end |
#request_headers ⇒ Object Also known as: req_headers
Returns a split array of headers. Example:
[
["GET / HTTP/1.1"],
["Host", "www.example.org"],
["User-Agent", "Mozilla/5.0 (..."],
...
]
69 70 71 72 73 |
# File 'lib/buby/implants/http_request_response.rb', line 69 def request_headers if headers=(@req_split ||= req_str.split(/\r?\n\r?\n/, 2))[0] @req_headers ||= headers.split(/\r?\n/).map {|h| h.split(/\s*:\s*/,2)} end end |
#request_str ⇒ Object Also known as: request_string, req_str
Returns the full request as a Ruby String - returns an empty string if request is nil.
55 56 57 |
# File 'lib/buby/implants/http_request_response.rb', line 55 def request_str return request().nil? ? "" : ::String.from_java_bytes(request()) end |
#response_body ⇒ Object Also known as: rsp_body
Returns the message body of the response, minus headers
46 47 48 |
# File 'lib/buby/implants/http_request_response.rb', line 46 def response_body (@rsp_split ||= rsp_str.split(/\r?\n\r?\n/, 2))[1] end |
#response_headers ⇒ Object Also known as: rsp_headers
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 ..."],
...
]
38 39 40 41 42 |
# File 'lib/buby/implants/http_request_response.rb', line 38 def response_headers if headers=(@rsp_split ||= rsp_str.split(/\r?\n\r?\n/, 2))[0] @rsp_headers ||= headers.split(/\r?\n/).map {|h| h.split(/\s*:\s*/,2)} end end |
#response_str ⇒ Object Also known as: response_string, rsp_str
returns the response as a Ruby String object - returns an empty string if response is nil.
24 25 26 |
# File 'lib/buby/implants/http_request_response.rb', line 24 def response_str return response().nil? ? "" : ::String.from_java_bytes(response()) end |
#uri ⇒ Object
Returns a Ruby URI object derived from the java.net.URL object
85 86 87 |
# File 'lib/buby/implants/http_request_response.rb', line 85 def uri @uri ||= URI.parse url.to_s if not url.nil? end |