def found_headers(self): headers = mime_headers.map(mime_headers.split(self.buffer)) collect = self.Collect(headers) if not collect.collector_is_simple: collect = collector.bind_complex(collector.Simple(), collect) # self.parts.append (collect) self.collect = collect self.collect_incoming_data = collect.collect_incoming_data self.found_terminator = self.found_boundary self.set_terminator(self.boundary) return False
def found_headers (self): headers = mime_headers.map (mime_headers.split (self.buffer)) collect = self.Collect (headers) if not collect.collector_is_simple: collect = collector.bind_complex ( collector.Simple (), collect ) # self.parts.append (collect) self.collect = collect self.collect_incoming_data = collect.collect_incoming_data self.found_terminator = self.found_boundary self.set_terminator (self.boundary) return False
def collector_continue (self, lines): self.collector_buffer = '' while (lines and not lines[0]): lines.pop (0) if not lines: return False # # From Medusa's http_server.py Original Comment: # # "as per the suggestion of http-1.1 section 4.1, (and # Eric Parker <*****@*****.**>), ignore a leading # blank lines (buggy browsers tack it onto the end of # POST requests)" - Sam Rushing # instanciate a reactor that will hold all states for the # HTTP request and response, and push it stalled in the # channel's output fifo. # http = Reactor () self.output_fifo.append (http) try: # split the request in: command, uri and version (method, url, version) = lines.pop (0).split (' ') except: # or return 400 Invalid and close the connection return http (400, CONNECTION_CLOSE) http.request = ( method.upper (), url, version.upper () ) # be liberal in what is accepted, strict to produce http.dispatcher = self # save and parse the collected lines and headers http.collector_lines = lines http.collector_headers = mime_headers.map (lines) # pass to the server's handlers, expect one of them to # complete the reactor's mime producer headers and body. if self.async_server.http_continue (http): return True # # A GET controller could very well ask to stall the # HTTP connection's collector (ie: to defer the # response to the current request and all the ones # pipelined there-after). return self.http_continue (http)
def collector_continue(self, lines): self.collector_buffer = '' while (lines and not lines[0]): lines.pop(0) if not lines: return False # # From Medusa's http_server.py Original Comment: # # "as per the suggestion of http-1.1 section 4.1, (and # Eric Parker <*****@*****.**>), ignore a leading # blank lines (buggy browsers tack it onto the end of # POST requests)" - Sam Rushing # instanciate a reactor that will hold all states for the # HTTP request and response, and push it stalled in the # channel's output fifo. # http = Reactor() self.output_fifo.append(http) try: # split the request in: command, uri and version (method, url, version) = lines.pop(0).split(' ') except: # or return 400 Invalid and close the connection return http(400, CONNECTION_CLOSE) http.request = (method.upper(), url, version.upper() ) # be liberal in what is accepted, strict to produce http.dispatcher = self # save and parse the collected lines and headers http.collector_lines = lines http.collector_headers = mime_headers.map(lines) # pass to the server's handlers, expect one of them to # complete the reactor's mime producer headers and body. if self.async_server.http_continue(http): return True # # A GET controller could very well ask to stall the # HTTP connection's collector (ie: to defer the # response to the current request and all the ones # pipelined there-after). return self.http_continue(http)
def collector_continue (self, lines): self.collector_buffer = '' while (lines and not lines[0]): lines.pop (0) if not lines: return self.closing # # make sure that the collector is stalled once the # dispatcher has been closed. self.pipelined_responses += 1 request = self.pipeline_responses[0] try: ( http_version, request.http_response ) = lines.pop (0).split (' ', 1) except: assert None == self.log ( 'invalid response line', 'debug' ) self.http_collector_error () return True self.http_version = http_version[-3:] request.collector_headers = mime_headers.map (lines) if ( request.http_method == 'HEAD' or request.http_response[:3] in ('204', '304', '305') ): self.collector_finalize () else: request.collector_body = request.http_collect () self.http_collector_continue ( request.collector_body, request.collector_headers ) return self.closing # stall the collector if closing