| Class | ServerSide::HTTP::Request |
| In: |
lib/serverside/http/request.rb
|
| Parent: | Object |
| HOST_PORT_RE | = | /^([^:]+):(.+)$/.freeze |
| body | [R] | |
| content_length | [R] | |
| cookies | [R] | |
| header_count | [R] | |
| headers | [R] | |
| http_version | [R] | |
| method | [R] | |
| params | [R] | |
| path | [R] | |
| persistent | [R] | |
| query | [R] | |
| request_line | [R] |
# File lib/serverside/http/request.rb, line 9
9: def initialize(conn)
10: @conn = conn
11: @headers = {}
12: @header_count = 0
13: @cookies = {}
14: end
Returns true if the accept header contains the supplied pattern.
# File lib/serverside/http/request.rb, line 62
62: def accept?(re)
63: re = Regexp.new(re) unless Regexp === re
64: (h = @headers[:accept]) && (h =~ re) && true
65: end
Returns the client name. The client name is either the value of the X-Forwarded-For header, or the result of get_peername.
# File lib/serverside/http/request.rb, line 49
49: def client_name
50: unless @client_name
51: @client_name = @headers[:x_forwarded_for]
52: unless @client_name
53: if addr = @conn.get_peername
54: p, @client_name = Socket.unpack_sockaddr_in(addr)
55: end
56: end
57: end
58: @client_name
59: end
# File lib/serverside/http/request.rb, line 71
71: def content_type
72: @headers[:content_type]
73: end
Parses the Host header.
# File lib/serverside/http/request.rb, line 36
36: def parse_host_header
37: h = @headers[:host]
38: if h =~ HOST_PORT_RE
39: @host = $1
40: @port = $2.to_i
41: else
42: @host = h
43: end
44: @host_header_parsed = true
45: end