new(m, reqbody, resbody, uri_or_path, initheader = nil) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/net/http/generic_request.rb, line 10
  def initialize(m, reqbody, resbody, uri_or_path, initheader = nil)
    @method = m
    @request_has_body = reqbody
    @response_has_body = resbody

    if URI === uri_or_path then
      @uri = uri_or_path.dup
      host = @uri.hostname
      host += ":#{@uri.port}" if @uri.port != @uri.class::DEFAULT_PORT
      path = uri_or_path.request_uri
    else
      @uri = nil
      host = nil
      path = uri_or_path
    end

    raise ArgumentError, "no HTTP request path given" unless path
    raise ArgumentError, "HTTP request path is empty" if path.empty?
    @path = path

    @decode_content = false

    if @response_has_body and Net::HTTP::HAVE_ZLIB then
      if !initheader ||
         !initheader.keys.any? { |k|
           ]accept-encoding range].include? k.downcase
         } then
        @decode_content = true
        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
    @body = nil
    @body_stream = nil
    @body_data = nil
  end
Register or log in to add new notes.