Class: GData::HTTP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gdata/http/request.rb

Overview

Very simple class to hold everything about an HTTP request.

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @url = url
  options.each do |key, value|
    self.send("#{key}=", value)
  end
  
  @method ||= :get
  @headers ||= {}
end

Instance Attribute Details

#bodyObject

The body of the request.



27
28
29
# File 'lib/gdata/http/request.rb', line 27

def body
  @body
end

#headersObject

The HTTP headers of the request.



31
32
33
# File 'lib/gdata/http/request.rb', line 31

def headers
  @headers
end

#methodObject

The HTTP method being used in the request.



29
30
31
# File 'lib/gdata/http/request.rb', line 29

def method
  @method
end

#urlObject

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.

Returns:

  • (Boolean)


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