parameters: (self)
return_statement: return True
docstring: Read self.rfile into self.inheaders. Return success.
docstring_summary: Read self.rfile into self.inheaders. Return success.
docstring_tokens: Read self . rfile into self . inheaders . Return success .
function: def read_request_headers(self):
          """Read self.rfile into self.inheaders. Return success."""
          
          # then all the http headers
          try:
              read_headers(self.rfile, self.inheaders)
          except ValueError:
              ex = sys.exc_info()[1]
              self.simple_response("400 Bad Request", ex.args[0])
              return False
          
          mrbs = self.server.max_request_body_size
          if mrbs and int(self.inheaders.get("Content-Length", 0)) > mrbs:
              self.simple_response("413 Request Entity Too Large",
                  "The entity sent with the request exceeds the maximum "
                  "allowed bytes.")
              return False
          
          # Persistent connection support
          if self.response_protocol == "HTTP/1.1":
              # Both server and client are HTTP/1.1
              if self.inheaders.get("Connection", "") == "close":
                  self.close_connection = True
          else:
              # Either the server or client (or both) are HTTP/1.0
              if self.inheaders.get("Connection", "") != "Keep-Alive":
                  self.close_connection = True
          
          # Transfer-Encoding support
          te = None
          if self.response_protocol == "HTTP/1.1":
              te = self.inheaders.get("Transfer-Encoding")
              if te:
                  te = [x.strip().lower() for x in te.split(",") if x.strip()]
          
          self.chunked_read = False
          
          if te:
              for enc in te:
                  if enc == "chunked":
                      self.chunked_read = True
                  else:
                      # Note that, even if we see "chunked", we must reject
                      # if there is an extension we don't recognize.
                      self.simple_response("501 Unimplemented")
                      self.close_connection = True
                      return False
          
          # From PEP 333:
          # "Servers and gateways that implement HTTP 1.1 must provide
          # transparent support for HTTP 1.1's "expect/continue" mechanism.
          # This may be done in any of several ways:
          #   1. Respond to requests containing an Expect: 100-continue request
          #      with an immediate "100 Continue" response, and proceed normally.
          #   2. Proceed with the request normally, but provide the application
          #      with a wsgi.input stream that will send the "100 Continue"
          #      response if/when the application first attempts to read from
          #      the input stream. The read request must then remain blocked
          #      until the client responds.
          #   3. Wait until the client decides that the server does not support
          #      expect/continue, and sends the request body on its own.
          #      (This is suboptimal, and is not recommended.)
          #
          # We used to do 3, but are now doing 1. Maybe we'll do 2 someday,
          # but it seems like it would be a big slowdown for such a rare case.
          if self.inheaders.get("Expect", "") == "100-continue":
              # Don't use simple_response here, because it emits headers
              # we don't want. See http://www.cherrypy.org/ticket/951
              msg = self.server.protocol + " 100 Continue\r\n\r\n"
              try:
                  self.conn.wfile.sendall(msg)
              except socket.error:
                  x = sys.exc_info()[1]
                  if x.args[0] not in socket_errors_to_ignore:
                      raise
          return True
function_tokens: def read_request_headers ( self ) : # then all the http headers try : read_headers ( self . rfile , self . inheaders ) except ValueError : ex = sys . exc_info ( ) [ 1 ] self . simple_response ( "400 Bad Request" , ex . args [ 0 ] ) return False mrbs = self . server . max_request_body_size if mrbs and int ( self . inheaders . get ( "Content-Length" , 0 ) ) > mrbs : self . simple_response ( "413 Request Entity Too Large" , "The entity sent with the request exceeds the maximum " "allowed bytes." ) return False # Persistent connection support if self . response_protocol == "HTTP/1.1" : # Both server and client are HTTP/1.1 if self . inheaders . get ( "Connection" , "" ) == "close" : self . close_connection = True else : # Either the server or client (or both) are HTTP/1.0 if self . inheaders . get ( "Connection" , "" ) != "Keep-Alive" : self . close_connection = True # Transfer-Encoding support te = None if self . response_protocol == "HTTP/1.1" : te = self . inheaders . get ( "Transfer-Encoding" ) if te : te = [ x . strip ( ) . lower ( ) for x in te . split ( "," ) if x . strip ( ) ] self . chunked_read = False if te : for enc in te : if enc == "chunked" : self . chunked_read = True else : # Note that, even if we see "chunked", we must reject # if there is an extension we don't recognize. self . simple_response ( "501 Unimplemented" ) self . close_connection = True return False # From PEP 333: # "Servers and gateways that implement HTTP 1.1 must provide # transparent support for HTTP 1.1's "expect/continue" mechanism. # This may be done in any of several ways: #   1. Respond to requests containing an Expect: 100-continue request #      with an immediate "100 Continue" response, and proceed normally. #   2. Proceed with the request normally, but provide the application #      with a wsgi.input stream that will send the "100 Continue" #      response if/when the application first attempts to read from #      the input stream. The read request must then remain blocked #      until the client responds. #   3. Wait until the client decides that the server does not support #      expect/continue, and sends the request body on its own. #      (This is suboptimal, and is not recommended.) # # We used to do 3, but are now doing 1. Maybe we'll do 2 someday, # but it seems like it would be a big slowdown for such a rare case. if self . inheaders . get ( "Expect" , "" ) == "100-continue" : # Don't use simple_response here, because it emits headers # we don't want. See http://www.cherrypy.org/ticket/951 msg = self . server . protocol + " 100 Continue\r\n\r\n" try : self . conn . wfile . sendall ( msg ) except socket . error : x = sys . exc_info ( ) [ 1 ] if x . args [ 0 ] not in socket_errors_to_ignore : raise return True