Class: Handsoap::Http::Part
- Inherits:
-
Object
- Object
- Handsoap::Http::Part
- Defined in:
- lib/handsoap/http.rb
Overview
Represents a HTTP Part. For simple HTTP-requests there is only one part, which is the response.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns a header.
-
#charset ⇒ Object
Returns the charset part of the content-type header.
-
#initialize(headers, body, parts = nil) ⇒ Part
constructor
A new instance of Part.
- #inspect(&block) ⇒ Object
-
#mime_type ⇒ Object
Returns the mime-type part of the content-type header.
- #multipart? ⇒ Boolean
Constructor Details
#initialize(headers, body, parts = nil) ⇒ Part
Returns a new instance of Part.
55 56 57 58 59 |
# File 'lib/handsoap/http.rb', line 55 def initialize(headers, body, parts = nil) @headers = headers @body = body @parts = parts end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
54 55 56 |
# File 'lib/handsoap/http.rb', line 54 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
54 55 56 |
# File 'lib/handsoap/http.rb', line 54 def headers @headers end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
54 55 56 |
# File 'lib/handsoap/http.rb', line 54 def parts @parts end |
Instance Method Details
#[](key) ⇒ Object
Returns a header. Returns String | Array | nil
62 63 64 65 |
# File 'lib/handsoap/http.rb', line 62 def [](key) key.to_s.downcase! (@headers[key] && @headers[key].length == 1) ? @headers[key].first : @headers[key] end |
#charset ⇒ Object
Returns the charset part of the content-type header
71 72 73 74 75 76 77 78 |
# File 'lib/handsoap/http.rb', line 71 def charset if @headers['content-type'] match_data = @headers['content-type'].first.match(/^[^;]+; charset=([^;]+)/) if match_data match_data[1].to_s end end end |
#inspect(&block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/handsoap/http.rb', line 82 def inspect(&block) str = inspect_head if headers.any? str << headers.map { |key,values| values.map {|value| Handsoap::Http.normalize_header_key(key) + ": " + value + "\n" }.join("") }.join("") end if body if multipart? if block_given? str << parts.map{|part| part.inspect(&block) }.join("") else str << parts.map{|part| part.inspect }.join("") end elsif body str << "---\n" if block_given? str << yield(body) else str << body end str << "\n---" end end end |
#mime_type ⇒ Object
Returns the mime-type part of the content-type header
67 68 69 |
# File 'lib/handsoap/http.rb', line 67 def mime_type @headers['content-type'].first.match(/^[^;]+/).to_s if @headers['content-type'] end |
#multipart? ⇒ Boolean
79 80 81 |
# File 'lib/handsoap/http.rb', line 79 def multipart? !! @parts end |