Class: Net::HTTPGenericRequest (Ruby 2.7.5)
Description: Class : Net::HTTPGenericRequest - Ruby 2.7.5

### Home Classes Methods

### In Files

- net/http/generic_request.rb

### Parent

Object

### Methods

- ::new
- #body=
- #body_exist?
- #body_stream=
- #inspect
- #request_body_permitted?
- #response_body_permitted?

### Included Modules

- Net::HTTPHeader

### Class/Module Index

Quicksearch

- EXCEPTION_TYPE
- EXCEPTION_TYPE
- EXCEPTION_TYPE
- EXCEPTION_TYPE
- HTTPClientException
- HTTPGatewayTimeOut
- HTTPMovedTemporarily
- HTTPMultipleChoice
- HTTPRequestEntityTooLarge
- HTTPRequestTimeOut
- HTTPRequestURITooLarge
- HTTPRequestURITooLong
- HTTPRequestURITooLong
- HTTPRequestedRangeNotSatisfiable
- Net
- Net::HTTP
- Net::HTTP::Copy
- Net::HTTP::Delete
- Net::HTTP::Get
- Net::HTTP::Head
- Net::HTTP::Lock
- Net::HTTP::Mkcol
- Net::HTTP::Move
- Net::HTTP::Options
- Net::HTTP::Patch
- Net::HTTP::Post
- Net::HTTP::Propfind
- Net::HTTP::Proppatch
- Net::HTTP::Put
- Net::HTTP::Trace
- Net::HTTP::Unlock
- Net::HTTPAccepted
- Net::HTTPAlreadyReported
- Net::HTTPBadGateway
- Net::HTTPBadRequest
- Net::HTTPClientError
- Net::HTTPConflict
- Net::HTTPContinue
- Net::HTTPCreated
- Net::HTTPEarlyHints
- Net::HTTPError
- Net::HTTPExceptions
- Net::HTTPExpectationFailed
- Net::HTTPFailedDependency
- Net::HTTPFatalError
- Net::HTTPForbidden
- Net::HTTPFound
- Net::HTTPGatewayTimeout
- Net::HTTPGenericRequest
- Net::HTTPGone
- Net::HTTPHeader
- Net::HTTPIMUsed
- Net::HTTPInformation
- Net::HTTPInsufficientStorage
- Net::HTTPInternalServerError
- Net::HTTPLengthRequired
- Net::HTTPLocked
- Net::HTTPLoopDetected
- Net::HTTPMethodNotAllowed
- Net::HTTPMisdirectedRequest
- Net::HTTPMovedPermanently
- Net::HTTPMultiStatus
- Net::HTTPMultipleChoices
- Net::HTTPNetworkAuthenticationRequired
- Net::HTTPNoContent
- Net::HTTPNonAuthoritativeInformation
- Net::HTTPNotAcceptable
- Net::HTTPNotExtended
- Net::HTTPNotFound
- Net::HTTPNotImplemented
- Net::HTTPNotModified
- Net::HTTPOK
- Net::HTTPPartialContent
- Net::HTTPPayloadTooLarge
- Net::HTTPPaymentRequired
- Net::HTTPPermanentRedirect
- Net::HTTPPreconditionFailed
- Net::HTTPPreconditionRequired
- Net::HTTPProcessing
- Net::HTTPProxyAuthenticationRequired
- Net::HTTPRangeNotSatisfiable
- Net::HTTPRedirection
- Net::HTTPRequest
- Net::HTTPRequestHeaderFieldsTooLarge
- Net::HTTPRequestTimeout
- Net::HTTPResetContent
- Net::HTTPResponse
- Net::HTTPRetriableError
- Net::HTTPSeeOther
- Net::HTTPServerError
- Net::HTTPServerException
- Net::HTTPServiceUnavailable
- Net::HTTPSuccess
- Net::HTTPSwitchProtocol
- Net::HTTPTemporaryRedirect
- Net::HTTPTooManyRequests
- Net::HTTPURITooLong
- Net::HTTPUnauthorized
- Net::HTTPUnavailableForLegalReasons
- Net::HTTPUnknownResponse
- Net::HTTPUnprocessableEntity
- Net::HTTPUnsupportedMediaType
- Net::HTTPUpgradeRequired
- Net::HTTPUseProxy
- Net::HTTPVariantAlsoNegotiates
- Net::HTTPVersionNotSupported

No matching classes.

# Net::HTTPGenericRequest

`HTTPGenericRequest` is the parent of the `Net::HTTPRequest` class. Do not use this directly; use a subclass of `Net::HTTPRequest`.

Mixes in the `Net::HTTPHeader` module to provide easier access to HTTP headers.

### Attributes

body[R]
body_stream[R]
decode_content[R]

Automatically set to false if the user sets the Accept-Encoding header. This indicates they wish to handle Content-encoding in responses themselves.

method[R]
path[R]
uri[R]

### Public Class Methods

new(m, reqbody, resbody, uri_or_path, initheader = nil) click to toggle source

                   # File net/http/generic_request.rb, line 11
    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
        raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
        raise ArgumentError, "no host component for URI" unless uri_or_path.hostname
        @uri = uri_or_path.dup
        host = @uri.hostname.dup
        host << ":".freeze << @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 @response_has_body and Net::HTTP::HAVE_ZLIB then
        if !initheader ||
           !initheader.keys.any? { |k|
             %w[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 if host
      @body = nil
      @body_stream = nil
      @body_data = nil
    end

### Public Instance Methods

body=(str) click to toggle source

                   # File net/http/generic_request.rb, line 93
    def body=(str)
      @body = str
      @body_stream = nil
      @body_data = nil
      str
    end

body_exist?() click to toggle source

                   # File net/http/generic_request.rb, line 86
    def body_exist?
      warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?", uplevel: 1 if $VERBOSE
      response_body_permitted?
    end

body_stream=(input) click to toggle source

                   # File net/http/generic_request.rb, line 102
    def body_stream=(input)
      @body = nil
      @body_stream = input
      @body_data = nil
      input
    end

inspect() click to toggle source

                   # File net/http/generic_request.rb, line 64
    def inspect
      "\#<#{self.class} #{@method}>"
    end

request_body_permitted?() click to toggle source

                   # File net/http/generic_request.rb, line 78
    def request_body_permitted?
      @request_has_body
    end

response_body_permitted?() click to toggle source

                   # File net/http/generic_request.rb, line 82
    def response_body_permitted?
      @response_has_body
    end