Method: Net::HTTPGenericRequest#initialize

Defined in:
lib/net/http/generic_request.rb

#initialize(m, reqbody, resbody, uri_or_path, initheader = nil) ⇒ HTTPGenericRequest

:nodoc:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/net/http/generic_request.rb', line 15

def initialize(m, reqbody, resbody, uri_or_path, initheader = nil) # :nodoc:
  @method = m
  @request_has_body = reqbody
  @response_has_body = resbody

  if URI === uri_or_path then
    raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
    hostname = uri_or_path.hostname
    raise ArgumentError, "no host component for URI" unless (hostname && hostname.length > 0)
    @uri = uri_or_path.dup
    host = @uri.hostname.dup
    host << ":" << @uri.port.to_s if @uri.port != @uri.default_port
    @path = uri_or_path.request_uri
    raise ArgumentError, "no HTTP request path given" unless @path
  else
    @uri = nil
    host = nil
    raise ArgumentError, "no HTTP request path given" unless uri_or_path
    raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty?
    @path = uri_or_path.dup
  end

  @decode_content = false

  if Net::HTTP::HAVE_ZLIB then
    if !initheader ||
       !initheader.keys.any? { |k|
         %w[accept-encoding range].include? k.downcase
       } then
      @decode_content = true if @response_has_body
      initheader = initheader ? initheader.dup : {}
      initheader["accept-encoding"] =
        "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
    end
  end

  initialize_http_header initheader
  self['Accept'] ||= '*/*'
  self['User-Agent'] ||= 'Ruby'
  self['Host'] ||= host if host
  @body = nil
  @body_stream = nil
  @body_data = nil
end