Class: Protocol::HTTP::Request

Inherits:
Object
  • Object
show all
Includes:
Body::Reader
Defined in:
lib/protocol/http/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Body::Reader

#body?, #close, #each, #finish, #read, #save

Constructor Details

#initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil) ⇒ Request

Returns a new instance of Request.


31
32
33
34
35
36
37
38
39
40
# File 'lib/protocol/http/request.rb', line 31

def initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil)
	@scheme = scheme
	@authority = authority
	@method = method
	@path = path
	@version = version
	@headers = headers
	@body = body
	@protocol = protocol
end

Instance Attribute Details

#authorityObject

Returns the value of attribute authority.


43
44
45
# File 'lib/protocol/http/request.rb', line 43

def authority
  @authority
end

#bodyObject

Returns the value of attribute body.


48
49
50
# File 'lib/protocol/http/request.rb', line 48

def body
  @body
end

#headersObject

Returns the value of attribute headers.


47
48
49
# File 'lib/protocol/http/request.rb', line 47

def headers
  @headers
end

#methodObject

Returns the value of attribute method.


44
45
46
# File 'lib/protocol/http/request.rb', line 44

def method
  @method
end

#pathObject

Returns the value of attribute path.


45
46
47
# File 'lib/protocol/http/request.rb', line 45

def path
  @path
end

#protocolObject

Returns the value of attribute protocol.


49
50
51
# File 'lib/protocol/http/request.rb', line 49

def protocol
  @protocol
end

#schemeObject

Returns the value of attribute scheme.


42
43
44
# File 'lib/protocol/http/request.rb', line 42

def scheme
  @scheme
end

#versionObject

Returns the value of attribute version.


46
47
48
# File 'lib/protocol/http/request.rb', line 46

def version
  @version
end

Class Method Details

.[](method, path, headers, body) ⇒ Object


64
65
66
67
68
69
# File 'lib/protocol/http/request.rb', line 64

def self.[](method, path, headers, body)
	body = Body::Buffered.wrap(body)
	headers = ::Protocol::HTTP::Headers[headers]
	
	self.new(nil, nil, method, path, nil, headers, body)
end

Instance Method Details

#call(connection) ⇒ Object

Send the request to the given connection.


52
53
54
# File 'lib/protocol/http/request.rb', line 52

def call(connection)
	connection.call(self)
end

#connect?Boolean

Returns:

  • (Boolean)

60
61
62
# File 'lib/protocol/http/request.rb', line 60

def connect?
	@method == Methods::CONNECT
end

#head?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'lib/protocol/http/request.rb', line 56

def head?
	@method == Methods::HEAD
end

#idempotent?Boolean

Returns:

  • (Boolean)

71
72
73
# File 'lib/protocol/http/request.rb', line 71

def idempotent?
	@method != Methods::POST && (@body.nil? || @body.empty?)
end

#to_sObject


75
76
77
# File 'lib/protocol/http/request.rb', line 75

def to_s
	"#{@scheme}://#{@authority}: #{@method} #{@path} #{@version}"
end