Пример #1
0
 def _input_start(self, stream_id, hdr_tuples):
     self.log.debug("request start %s %s" % (stream_id, hdr_tuples))
     method = get_hdr(hdr_tuples, 'method')[0] # FIXME: error handling
     uri = get_hdr(hdr_tuples, 'url')[0] # FIXME: error handling
     assert not self._streams.has_key(stream_id) # FIXME
     def res_start(*args):
         return self.res_start(stream_id, *args)
     # TODO: sanity checks / catch errors from requst_handler
     self._streams[stream_id] = self.request_handler(
         method, uri, hdr_tuples, res_start, self.req_body_pause)
Пример #2
0
    def _input_start(self, stream_id, stream_priority, hdr_tuples):
        self.log.debug("request start %s %s" % (stream_id, hdr_tuples))
        method = get_hdr(hdr_tuples, 'method')[0]  # FIXME: error handling
        uri = get_hdr(hdr_tuples, 'url')[0]  # FIXME: error handling
        assert not self._streams.has_key(stream_id)  # FIXME

        def res_start(*args):
            return self.res_start(stream_id, stream_priority, *args)

        # TODO: sanity checks / catch errors from requst_handler
        self._streams[stream_id] = self.request_handler(
            method, uri, hdr_tuples, res_start, self.req_body_pause)
Пример #3
0
 def _input_start(self, stream_id, hdr_tuples):
     """
     Take the top set of headers from the input stream, parse them
     and queue the request to be processed by the application.
     """
     status = get_hdr(hdr_tuples, 'status')[0]
     try:
         res_code, res_phrase = status.split(None, 1)
     except ValueError:
         res_code = status.rstrip()
         res_phrase = ""
     self._streams[stream_id][1:2] = self._streams[stream_id][0](
         "HTTP/1.1", res_code, res_phrase, hdr_tuples, self.res_body_pause)
Пример #4
0
 def _input_start(self, stream_id, stream_priority, hdr_tuples):
     """
     Take the top set of headers from the input stream, parse them
     and queue the request to be processed by the application.
     """
     status = get_hdr(hdr_tuples, 'status')[0]
     try:
         res_code, res_phrase = status.split(None, 1)
     except ValueError:
         res_code = status.rstrip()
         res_phrase = ""
     self._streams[stream_id][1:2] = self._streams[stream_id][0](
         "HTTP/1.1", res_code, res_phrase, hdr_tuples, self.res_body_pause)
Пример #5
0
 def req_start(self, method, uri, req_hdrs, req_body_pause):
     """
     Start a request to uri using method, where 
     req_hdrs is a list of (field_name, field_value) for
     the request headers.
     
     Returns a (req_body, req_done) tuple.
     """
     self._req_body_pause_cb = req_body_pause
     req_hdrs = [i for i in req_hdrs \
         if not i[0].lower() in req_remove_hdrs]
     (scheme, authority, path, query, fragment) = urlsplit(uri)
     if scheme.lower() != 'http':
         self._handle_error(ERR_URL, "Only HTTP URLs are supported")
         return dummy, dummy
     if "@" in authority:
         userinfo, authority = authority.split("@", 1)
     if ":" in authority:
         self._host, port = authority.rsplit(":", 1)
         try:
             self._port = int(port)
         except ValueError:
             self._handle_error(ERR_URL, "Non-integer port in URL")
             return dummy, dummy
     else:
         self._host, self._port = authority, 80
     if path == "":
         path = "/"
     uri = urlunsplit(('', '', path, query, ''))
     self.method, self.uri, self.req_hdrs = method, uri, req_hdrs
     self.req_hdrs.append(("Host", authority))
     self.req_hdrs.append(("Connection", "keep-alive"))
     try:
         body_len = int(get_hdr(req_hdrs, "content-length").pop(0))
         delimit = COUNTED
     except (IndexError, ValueError):
         body_len = None
         delimit = NOBODY
     self._output_start("%s %s HTTP/1.1" % (self.method, self.uri),
         self.req_hdrs, delimit
     )
     _idle_pool.attach(self._host, self._port, self._handle_connect,
         self._handle_connect_error, self.connect_timeout
     )
     return self.req_body, self.req_done
Пример #6
0
 def req_start(self, method, uri, req_hdrs, req_body_pause):
     """
     Start a request to uri using method, where 
     req_hdrs is a list of (field_name, field_value) for
     the request headers.
     
     Returns a (req_body, req_done) tuple.
     """
     self._req_body_pause_cb = req_body_pause
     req_hdrs = [i for i in req_hdrs \
         if not i[0].lower() in req_remove_hdrs]
     (scheme, authority, path, query, fragment) = urlsplit(uri)
     if scheme.lower() != 'http':
         self._handle_error(ERR_URL, "Only HTTP URLs are supported")
         return dummy, dummy
     if "@" in authority:
         userinfo, authority = authority.split("@", 1)
     if ":" in authority:
         self._host, port = authority.rsplit(":", 1)
         try:
             self._port = int(port)
         except ValueError:
             self._handle_error(ERR_URL, "Non-integer port in URL")
             return dummy, dummy
     else:
         self._host, self._port = authority, 80
     if path == "":
         path = "/"
     uri = urlunsplit(('', '', path, query, ''))
     self.method, self.uri, self.req_hdrs = method, uri, req_hdrs
     self.req_hdrs.append(("Host", authority))
     self.req_hdrs.append(("Connection", "keep-alive"))
     try:
         body_len = int(get_hdr(req_hdrs, "content-length").pop(0))
         delimit = COUNTED
     except (IndexError, ValueError):
         body_len = None
         delimit = NOBODY
     self._output_start("%s %s HTTP/1.1" % (self.method, self.uri),
                        self.req_hdrs, delimit)
     _idle_pool.attach(self._host, self._port, self._handle_connect,
                       self._handle_connect_error, self.connect_timeout)
     return self.req_body, self.req_done
Пример #7
0
    def res_start(self, status_code, status_phrase, res_hdrs, res_body_pause):
        "Start a response. Must only be called once per response."
        self._res_body_pause_cb = res_body_pause
        res_hdrs = [i for i in res_hdrs if not i[0].lower() in hop_by_hop_hdrs]

        try:
            body_len = int(get_hdr(res_hdrs, "content-length").pop(0))
        except (IndexError, ValueError):
            body_len = None
        if body_len is not None:
            delimit = COUNTED
            res_hdrs.append(("Connection", "keep-alive"))
        elif 2.0 > self.req_version >= 1.1:
            delimit = CHUNKED
            res_hdrs.append(("Transfer-Encoding", "chunked"))
        else:
            delimit = CLOSE
            res_hdrs.append(("Connection", "close"))

        self._output_start("HTTP/1.1 %s %s" % (status_code, status_phrase), res_hdrs, delimit)
        return self.res_body, self.res_done
Пример #8
0
    def res_start(self, status_code, status_phrase, res_hdrs, res_body_pause):
        "Start a response. Must only be called once per response."
        self._res_body_pause_cb = res_body_pause
        res_hdrs = [i for i in res_hdrs \
                    if not i[0].lower() in hop_by_hop_hdrs ]

        try:
            body_len = int(get_hdr(res_hdrs, "content-length").pop(0))
        except (IndexError, ValueError):
            body_len = None
        if body_len is not None:
            delimit = COUNTED
            res_hdrs.append(("Connection", "keep-alive"))
        elif 2.0 > self.req_version >= 1.1:
            delimit = CHUNKED
            res_hdrs.append(("Transfer-Encoding", "chunked"))
        else:
            delimit = CLOSE
            res_hdrs.append(("Connection", "close"))

        self._output_start("HTTP/1.1 %s %s" % (status_code, status_phrase),
                           res_hdrs, delimit)
        return self.res_body, self.res_done