123456789_123456789_123456789_123456789_123456789_

Class: WEBrick::HTTPRequest

Relationships & Source Files
Inherits: Object
Defined in: lib/webrick/https.rb,
lib/webrick/httprequest.rb

Request line

Request-URI

Header and entity body

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(config) ⇒ HTTPRequest

Creates a new HTTP request. Config::HTTP is the default configuration.

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 151

def initialize(config)
  @config = config
  @buffer_size = @config[:InputBufferSize]
  @logger = config[:Logger]

  @request_line = @request_method =
    @unparsed_uri = @http_version = nil

  @request_uri = @host = @port = @path = nil
  @script_name = @path_info = nil
  @query_string = nil
  @query = nil
  @form_data = nil

  @raw_header = Array.new
  @header = nil
  @cookies = []
  @accept = []
  @accept_charset = []
  @accept_encoding = []
  @accept_language = []
  @body = ""

  @addr = @peeraddr = nil
  @attributes = {}
  @user = nil
  @keep_alive = false
  @request_time = nil

  @remaining_size = nil
  @socket = nil

  @forwarded_proto = @forwarded_host = @forwarded_port =
    @forwarded_server = @forwarded_for = nil
end

Instance Attribute Details

#accept (readonly)

The Accept header value

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 98

attr_reader :accept

#accept_charset (readonly)

The Accept-Charset header value

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 103

attr_reader :accept_charset

#accept_encoding (readonly)

The Accept-Encoding header value

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 108

attr_reader :accept_encoding

#accept_language (readonly)

The Accept-Language header value

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 113

attr_reader :accept_language

#addr (readonly)

The socket address of the server

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 125

attr_reader :addr

#attributes (readonly)

Hash of request attributes

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 135

attr_reader :attributes

#cipher (readonly)

HTTP request SSL cipher

[ GitHub ]

  
# File 'lib/webrick/https.rb', line 27

attr_reader :cipher

#client_cert (readonly)

HTTP request client certificate

[ GitHub ]

  
# File 'lib/webrick/https.rb', line 37

attr_reader :client_cert

#cookies (readonly)

The parsed request cookies

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 93

attr_reader :cookies

#header (readonly)

The parsed header of the request

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 88

attr_reader :header

#http_version (readonly)

The HTTP version of the request

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 49

attr_reader :http_version

#keep_alive (readonly)

Is this a keep-alive connection?

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 140

attr_reader :keep_alive

#keep_alive?Boolean (readonly)

Should the connection this request was made on be kept alive?

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 343

def keep_alive?
  @keep_alive
end

#path (readonly)

The request path

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 61

attr_reader :path

#path_info (rw)

The path info (CGI variable)

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 71

attr_accessor :path_info

#peeraddr (readonly)

The socket address of the client

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 130

attr_reader :peeraddr

#query_string (rw)

The query from the URI of the request

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 76

attr_accessor :query_string

#raw_header (readonly)

The raw header of the request

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 83

attr_reader :raw_header

#request_line (readonly)

The complete request line such as:

GET / HTTP/1.1
[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 34

attr_reader :request_line

#request_method (readonly)

The request method, GET, POST, PUT, etc.

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 39

attr_reader :request_method

#request_time (readonly)

The local time this request was received

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 145

attr_reader :request_time

#request_uri (readonly)

The parsed URI of the request

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 56

attr_reader :request_uri

#script_name (rw)

The script name (CGI variable)

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 66

attr_accessor :script_name

#server_cert (readonly)

HTTP request server certificate

[ GitHub ]

  
# File 'lib/webrick/https.rb', line 32

attr_reader :server_cert

#ssl?Boolean (readonly)

Is this an SSL request?

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 336

def ssl?
  return @request_uri.scheme == "https"
end

#unparsed_uri (readonly)

The unparsed URI of the request

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 44

attr_reader :unparsed_uri

#user (rw)

The remote user (CGI variable)

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 120

attr_accessor :user

Instance Method Details

#[](header_name)

Retrieves header_name

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 286

def [](header_name)
  if @header
    value = @header[header_name.downcase]
    value.empty? ? nil : value.join(", ")
  end
end

#body(&block)

Returns the request body.

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 253

def body(&block) # :yields: body_chunk
  block ||= Proc.new{|chunk| @body << chunk }
  read_body(@socket, block)
  @body.empty? ? nil : @body
end

#content_length

The content-length header

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 272

def content_length
  return Integer(self['content-length'])
end

#content_type

The content-type header

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 279

def content_type
  return self['content-type']
end

#each

Iterates over the request headers

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 296

def each
  if @header
    @header.each{|k, v|
      value = @header[k]
      yield(k, value.empty? ? nil : value.join(", "))
    }
  end
end

#host

The host this request is for

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 308

def host
  return @forwarded_host || @host
end

#port

The port this request is for

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 315

def port
  return @forwarded_port || @port
end

#query

Request query as a Hash

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 262

def query
  unless @query
    parse_query()
  end
  @query
end

#remote_ip

The client's IP address

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 329

def remote_ip
  return self["client-ip"] || @forwarded_for || @peeraddr[3]
end

#server_name

The server name this request is for

[ GitHub ]

  
# File 'lib/webrick/httprequest.rb', line 322

def server_name
  return @forwarded_server || @config[:ServerName]
end