Class: Net::HTTPGenericRequest

Inherits:
Object
  • Object
show all
Includes:
HTTPHeader
Defined in:
lib/extensions/net-http/net/http.rb

Overview

Parent of HTTPRequest class. Do not use this directly; use a subclass of HTTPRequest.

Mixes in the HTTPHeader module.

Direct Known Subclasses

HTTPRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTTPHeader

#[], #[]=, #add_field, #basic_auth, #chunked?, #connection_close?, #connection_keep_alive?, #content_length, #content_length=, #content_range, #content_type, #delete, #each_capitalized, #each_capitalized_name, #each_header, #each_name, #each_value, #fetch, #get_fields, #initialize_http_header, #key?, #main_type, #proxy_basic_auth, #range, #range_length, #set_content_type, #set_form_data, #set_range, #size, #sub_type, #to_hash, #type_params

Constructor Details

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

Returns a new instance of HTTPGenericRequest.

Raises:

  • (ArgumentError)


1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
# File 'lib/extensions/net-http/net/http.rb', line 1684

def initialize(m, reqbody, resbody, path, initheader = nil)
  @method = m
  @request_has_body = reqbody
  @response_has_body = resbody
  raise ArgumentError, "no HTTP request path given" unless path
  raise ArgumentError, "HTTP request path is empty" if path.empty?
  @path = path
  initialize_http_header initheader
  self['Accept'] ||= '*/*'
  self['User-Agent'] ||= 'Ruby'
  @body = nil
  @body_stream = nil
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



1718
1719
1720
# File 'lib/extensions/net-http/net/http.rb', line 1718

def body
  @body
end

#body_streamObject

Returns the value of attribute body_stream.



1726
1727
1728
# File 'lib/extensions/net-http/net/http.rb', line 1726

def body_stream
  @body_stream
end

#methodObject (readonly)

Returns the value of attribute method.



1698
1699
1700
# File 'lib/extensions/net-http/net/http.rb', line 1698

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



1699
1700
1701
# File 'lib/extensions/net-http/net/http.rb', line 1699

def path
  @path
end

Instance Method Details

#body_exist?Boolean

Returns:

  • (Boolean)


1713
1714
1715
1716
# File 'lib/extensions/net-http/net/http.rb', line 1713

def body_exist?
  warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?" if $VERBOSE
  response_body_permitted?
end

#exec(sock, ver, path) ⇒ Object

write



1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/extensions/net-http/net/http.rb', line 1743

def exec(sock, ver, path)   #:nodoc: internal use only
  if @body
    send_request_with_body sock, ver, path, @body
  elsif @body_stream
    send_request_with_body_stream sock, ver, path, @body_stream
  else
    write_header sock, ver, path
  end
end

#inspectObject



1701
1702
1703
# File 'lib/extensions/net-http/net/http.rb', line 1701

def inspect
  "\#<#{self.class} #{@method}>"
end

#request_body_permitted?Boolean

Returns:

  • (Boolean)


1705
1706
1707
# File 'lib/extensions/net-http/net/http.rb', line 1705

def request_body_permitted?
  @request_has_body
end

#response_body_permitted?Boolean

Returns:

  • (Boolean)


1709
1710
1711
# File 'lib/extensions/net-http/net/http.rb', line 1709

def response_body_permitted?
  @response_has_body
end

#set_body_internal(str) ⇒ Object

:nodoc: internal use only

Raises:

  • (ArgumentError)


1734
1735
1736
1737
# File 'lib/extensions/net-http/net/http.rb', line 1734

def set_body_internal(str)   #:nodoc: internal use only
  raise ArgumentError, "both of body argument and HTTPRequest#body set" if str and (@body or @body_stream)
  self.body = str if str
end