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

Attributes

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

Public Class methods

[Source]

      # File lib/net/http.rb, line 1463
1463:     def initialize(m, reqbody, resbody, path, initheader = nil)
1464:       @method = m
1465:       @request_has_body = reqbody
1466:       @response_has_body = resbody
1467:       raise ArgumentError, "HTTP request path is empty" if path.empty?
1468:       @path = path
1469:       initialize_http_header initheader
1470:       self['Accept'] ||= '*/*'
1471:       @body = nil
1472:       @body_stream = nil
1473:     end

Public Instance methods

[Source]

      # File lib/net/http.rb, line 1497
1497:     def body=(str)
1498:       @body = str
1499:       @body_stream = nil
1500:       str
1501:     end

[Source]

      # File lib/net/http.rb, line 1490
1490:     def body_exist?
1491:       warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?" if $VERBOSE
1492:       response_body_permitted?
1493:     end

[Source]

      # File lib/net/http.rb, line 1505
1505:     def body_stream=(input)
1506:       @body = nil
1507:       @body_stream = input
1508:       input
1509:     end

[Source]

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

[Source]

      # File lib/net/http.rb, line 1482
1482:     def request_body_permitted?
1483:       @request_has_body
1484:     end

[Source]

      # File lib/net/http.rb, line 1486
1486:     def response_body_permitted?
1487:       @response_has_body
1488:     end

Private Instance methods

[Source]

      # File lib/net/http.rb, line 1532
1532:     def send_request_with_body(sock, ver, path, body)
1533:       self.content_length = body.length
1534:       delete 'Transfer-Encoding'
1535:       supply_default_content_type
1536:       write_header sock, ver, path
1537:       sock.write body
1538:     end

[Source]

      # File lib/net/http.rb, line 1540
1540:     def send_request_with_body_stream(sock, ver, path, f)
1541:       unless content_length() or chunked?
1542:         raise ArgumentError,
1543:             "Content-Length not given and Transfer-Encoding is not `chunked'"
1544:       end
1545:       supply_default_content_type
1546:       write_header sock, ver, path
1547:       if chunked?
1548:         while s = f.read(1024)
1549:           sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
1550:         end
1551:         sock.write "0\r\n\r\n"
1552:       else
1553:         while s = f.read(1024)
1554:           sock.write s
1555:         end
1556:       end
1557:     end

[Source]

      # File lib/net/http.rb, line 1559
1559:     def supply_default_content_type
1560:       return if content_type()
1561:       warn 'net/http: warning: Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE
1562:       set_content_type 'application/x-www-form-urlencoded'
1563:     end

[Source]

      # File lib/net/http.rb, line 1565
1565:     def write_header(sock, ver, path)
1566:       buf = "#{@method} #{path} HTTP/#{ver}\r\n"
1567:       each_capitalized do |k,v|
1568:         buf << "#{k}: #{v}\r\n"
1569:       end
1570:       buf << "\r\n"
1571:       sock.write buf
1572:     end

[Validate]