Class Net::HTTPGenericRequest
In: lib/net/http.rb
Parent: Object

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

Mixes in the HTTPHeader module.

Methods

Included Modules

HTTPHeader

Constants

BUFSIZE = 16*1024

Attributes

body  [R] 
body_stream  [R] 
method  [R] 
path  [R] 

Public Class methods

[Source]

      # File lib/net/http.rb, line 1474
1474:     def initialize(m, reqbody, resbody, path, initheader = nil)
1475:       @method = m
1476:       @request_has_body = reqbody
1477:       @response_has_body = resbody
1478:       raise ArgumentError, "HTTP request path is empty" if path.empty?
1479:       @path = path
1480:       initialize_http_header initheader
1481:       self['Accept'] ||= '*/*'
1482:       @body = nil
1483:       @body_stream = nil
1484:     end

Public Instance methods

[Source]

      # File lib/net/http.rb, line 1508
1508:     def body=(str)
1509:       @body = str
1510:       @body_stream = nil
1511:       str
1512:     end

[Source]

      # File lib/net/http.rb, line 1501
1501:     def body_exist?
1502:       warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?" if $VERBOSE
1503:       response_body_permitted?
1504:     end

[Source]

      # File lib/net/http.rb, line 1516
1516:     def body_stream=(input)
1517:       @body = nil
1518:       @body_stream = input
1519:       input
1520:     end

[Source]

      # File lib/net/http.rb, line 1489
1489:     def inspect
1490:       "\#<#{self.class} #{@method}>"
1491:     end

[Source]

      # File lib/net/http.rb, line 1493
1493:     def request_body_permitted?
1494:       @request_has_body
1495:     end

[Source]

      # File lib/net/http.rb, line 1497
1497:     def response_body_permitted?
1498:       @response_has_body
1499:     end

Private Instance methods

[Source]

      # File lib/net/http.rb, line 1543
1543:     def send_request_with_body(sock, ver, path, body)
1544:       self.content_length = body.length
1545:       delete 'Transfer-Encoding'
1546:       supply_default_content_type
1547:       write_header sock, ver, path
1548:       sock.write body
1549:     end

[Source]

      # File lib/net/http.rb, line 1551
1551:     def send_request_with_body_stream(sock, ver, path, f)
1552:       unless content_length() or chunked?
1553:         raise ArgumentError,
1554:             "Content-Length not given and Transfer-Encoding is not `chunked'"
1555:       end
1556:       supply_default_content_type
1557:       write_header sock, ver, path
1558:       if chunked?
1559:         while s = f.read(BUFSIZE)
1560:           sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
1561:         end
1562:         sock.write "0\r\n\r\n"
1563:       else
1564:         while s = f.read(BUFSIZE)
1565:           sock.write s
1566:         end
1567:       end
1568:     end

[Source]

      # File lib/net/http.rb, line 1570
1570:     def supply_default_content_type
1571:       return if content_type()
1572:       warn 'net/http: warning: Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE
1573:       set_content_type 'application/x-www-form-urlencoded'
1574:     end

[Source]

      # File lib/net/http.rb, line 1576
1576:     def write_header(sock, ver, path)
1577:       buf = "#{@method} #{path} HTTP/#{ver}\r\n"
1578:       each_capitalized do |k,v|
1579:         buf << "#{k}: #{v}\r\n"
1580:       end
1581:       buf << "\r\n"
1582:       sock.write buf
1583:     end

[Validate]