Class ServerSide::HTTP::Request
In: lib/serverside/http/request.rb
Parent: Object

Methods

Included Modules

ServerSide::HTTP::Parsing

Constants

HOST_PORT_RE = /^([^:]+):(.+)$/.freeze

Attributes

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] 

Public Class methods

[Source]

    # 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

Public Instance methods

Returns true if the accept header contains the supplied pattern.

[Source]

    # 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.

[Source]

    # 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

[Source]

    # File lib/serverside/http/request.rb, line 71
71:     def content_type
72:       @headers[:content_type]
73:     end

Returns true if the request was received on port 443

[Source]

    # File lib/serverside/http/request.rb, line 29
29:     def encrypted?
30:       port == 443
31:     end

Returns the host specified in the Host header.

[Source]

    # File lib/serverside/http/request.rb, line 17
17:     def host
18:       parse_host_header unless @host_header_parsed
19:       @host
20:     end

Parses the Host header.

[Source]

    # 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

Returns the port number if specified in the Host header.

[Source]

    # File lib/serverside/http/request.rb, line 23
23:     def port
24:       parse_host_header unless @host_header_parsed
25:       @port
26:     end

[Source]

    # File lib/serverside/http/request.rb, line 67
67:     def user_agent
68:       @headers[:user_agent]
69:     end

[Validate]