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.
33 34 35 36 37 38 39 40 41 |
# File 'lib/gdata/http/request.rb', line 33 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.
26 27 28 |
# File 'lib/gdata/http/request.rb', line 26 def body @body end |
#headers ⇒ Object
The HTTP headers of the request.
30 31 32 |
# File 'lib/gdata/http/request.rb', line 30 def headers @headers end |
#method ⇒ Object
The HTTP method being used in the request.
28 29 30 |
# File 'lib/gdata/http/request.rb', line 28 def method @method end |
#url ⇒ Object
The URL of the request.
24 25 26 |
# File 'lib/gdata/http/request.rb', line 24 def url @url end |
Instance Method Details
#calculate_length! ⇒ Object
Calculates and sets the length of the body.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gdata/http/request.rb', line 62 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.
53 54 55 56 57 58 59 |
# File 'lib/gdata/http/request.rb', line 53 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.
44 45 46 47 48 49 50 |
# File 'lib/gdata/http/request.rb', line 44 def chunked? if @headers['Transfer-Encoding'] == 'chunked' return true else return false end end |