Class: GData::HTTP::Request
- Inherits:
-
Object
- Object
- GData::HTTP::Request
- Defined in:
- lib/gdata/http/request.rb
Overview
Very simple class to hold everything about an HTTP request.
Instance Attribute Summary collapse
-
#body ⇒ Object
The body of the request.
-
#headers ⇒ Object
The HTTP headers of the request.
-
#method ⇒ Object
The HTTP method being used in the request.
-
#url ⇒ Object
The URL of the request.
Instance Method Summary collapse
-
#calculate_length! ⇒ Object
Calculates and sets the length of the body.
-
#chunked=(enabled) ⇒ Object
Sets if the request is using chunked transfer-encoding.
-
#chunked? ⇒ Boolean
Returns whether or not a request is chunked.
-
#initialize(url, options = {}) ⇒ Request
constructor
Only the URL itself is required, everything else is optional.
Constructor Details
#initialize(url, options = {}) ⇒ Request
Only the URL itself is required, everything else is optional.
34 35 36 37 38 39 40 41 42 |
# File 'lib/gdata/http/request.rb', line 34 def initialize(url, = {}) @url = url .each do |key, value| self.send("#{key}=", value) end @method ||= :get @headers ||= {} end |
Instance Attribute Details
#body ⇒ Object
The body of the request.
27 28 29 |
# File 'lib/gdata/http/request.rb', line 27 def body @body end |
#headers ⇒ Object
The HTTP headers of the request.
31 32 33 |
# File 'lib/gdata/http/request.rb', line 31 def headers @headers end |
#method ⇒ Object
The HTTP method being used in the request.
29 30 31 |
# File 'lib/gdata/http/request.rb', line 29 def method @method end |
#url ⇒ Object
The URL of the request.
25 26 27 |
# File 'lib/gdata/http/request.rb', line 25 def url @url end |
Instance Method Details
#calculate_length! ⇒ Object
Calculates and sets the length of the body.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gdata/http/request.rb', line 63 def calculate_length! if not @headers['Content-Length'] and not chunked? \ and method != :get and method != :delete if @body @headers['Content-Length'] = @body.length else @headers['Content-Length'] = 0 end end end |
#chunked=(enabled) ⇒ Object
Sets if the request is using chunked transfer-encoding.
54 55 56 57 58 59 60 |
# File 'lib/gdata/http/request.rb', line 54 def chunked=(enabled) if enabled @headers['Transfer-Encoding'] = 'chunked' else @headers.delete('Transfer-Encoding') end end |
#chunked? ⇒ Boolean
Returns whether or not a request is chunked.
45 46 47 48 49 50 51 |
# File 'lib/gdata/http/request.rb', line 45 def chunked? if @headers['Transfer-Encoding'] == 'chunked' return true else return false end end |