Class: Handsoap::Http::Part
- Inherits:
-
Object
- Object
- Handsoap::Http::Part
- Defined in:
- lib/handsoap/http/part.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.
11 12 13 14 15 |
# File 'lib/handsoap/http/part.rb', line 11 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.
9 10 11 |
# File 'lib/handsoap/http/part.rb', line 9 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/handsoap/http/part.rb', line 9 def headers @headers end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
9 10 11 |
# File 'lib/handsoap/http/part.rb', line 9 def parts @parts end |
Instance Method Details
#[](key) ⇒ Object
Returns a header. Returns String | Array | nil
19 20 21 22 |
# File 'lib/handsoap/http/part.rb', line 19 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
30 31 32 33 34 35 36 37 |
# File 'lib/handsoap/http/part.rb', line 30 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/handsoap/http/part.rb', line 43 def inspect(&block) str = inspect_head if headers.any? str << headers.map { |key,values| values.map {|value| 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
25 26 27 |
# File 'lib/handsoap/http/part.rb', line 25 def mime_type @headers['content-type'].first.match(/^[^;]+/).to_s if @headers['content-type'] end |
#multipart? ⇒ Boolean
39 40 41 |
# File 'lib/handsoap/http/part.rb', line 39 def multipart? !! @parts end |