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.



33
34
35
36
37
38
39
40
41
# File 'lib/gdata/http/request.rb', line 33

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.



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

def body
  @body
end

#headersObject

The HTTP headers of the request.



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

def headers
  @headers
end

#methodObject

The HTTP method being used in the request.



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

def method
  @method
end

#urlObject

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.

Returns:

  • (Boolean)


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