當前位置: 首頁>>代碼示例>>Python>>正文


Python httputil.ResponseStartLine方法代碼示例

本文整理匯總了Python中tornado.httputil.ResponseStartLine方法的典型用法代碼示例。如果您正苦於以下問題:Python httputil.ResponseStartLine方法的具體用法?Python httputil.ResponseStartLine怎麽用?Python httputil.ResponseStartLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.httputil的用法示例。


在下文中一共展示了httputil.ResponseStartLine方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: respond_204

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def respond_204(self, request):
        self.http1 = request.version.startswith('HTTP/1.')
        if not self.http1:
            # Close the request cleanly in HTTP/2; it will be skipped anyway.
            request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
                                             HTTPHeaders())
            request.connection.finish()
            return
        # A 204 response never has a body, even if doesn't have a content-length
        # (which would otherwise mean read-until-close).  Tornado always
        # sends a content-length, so we simulate here a server that sends
        # no content length and does not close the connection.
        #
        # Tests of a 204 response with a Content-Length header are included
        # in SimpleHTTPClientTestMixin.
        stream = request.connection.detach()
        stream.write(
            b"HTTP/1.1 204 No content\r\n\r\n")
        stream.close() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:simple_httpclient_test.py

示例2: headers_received

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def headers_received(
        self,
        first_line: Union[httputil.ResponseStartLine, httputil.RequestStartLine],
        headers: httputil.HTTPHeaders,
    ) -> None:
        assert isinstance(first_line, httputil.ResponseStartLine)
        if self.request.expect_100_continue and first_line.code == 100:
            await self._write_body(False)
            return
        self.code = first_line.code
        self.reason = first_line.reason
        self.headers = headers

        if self._should_follow_redirect():
            return

        if self.request.header_callback is not None:
            # Reassemble the start line.
            self.request.header_callback("%s %s %s\r\n" % first_line)
            for k, v in self.headers.get_all():
                self.request.header_callback("%s: %s\r\n" % (k, v))
            self.request.header_callback("\r\n") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:24,代碼來源:simple_httpclient.py

示例3: headers_received

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def headers_received(
        self,
        start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
        headers: httputil.HTTPHeaders,
    ) -> Optional[Awaitable[None]]:
        assert isinstance(start_line, httputil.RequestStartLine)
        request = httputil.HTTPServerRequest(
            connection=self.request_conn,
            server_connection=self.server_conn,
            start_line=start_line,
            headers=headers,
        )

        self.delegate = self.router.find_handler(request)
        if self.delegate is None:
            app_log.debug(
                "Delegate for %s %s request not found",
                start_line.method,
                start_line.path,
            )
            self.delegate = _DefaultMessageDelegate(self.request_conn)

        return self.delegate.headers_received(start_line, headers) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:25,代碼來源:routing.py

示例4: respond_204

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def respond_204(self, request):
        self.http1 = request.version.startswith('HTTP/1.')
        if not self.http1:
            # Close the request cleanly in HTTP/2; it will be skipped anyway.
            request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
                                             HTTPHeaders())
            request.connection.finish()
            return

        # A 204 response never has a body, even if doesn't have a content-length
        # (which would otherwise mean read-until-close).  We simulate here a
        # server that sends no content length and does not close the connection.
        #
        # Tests of a 204 response with no Content-Length header are included
        # in SimpleHTTPClientTestMixin.
        stream = request.connection.detach()
        stream.write(b"HTTP/1.1 204 No content\r\n")
        if request.arguments.get("error", [False])[-1]:
            stream.write(b"Content-Length: 5\r\n")
        else:
            stream.write(b"Content-Length: 0\r\n")
        stream.write(b"\r\n")
        stream.close() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:25,代碼來源:simple_httpclient_test.py

示例5: _check_header_length

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def _check_header_length(self):
        if (sum(len(f.data) for f in self._header_frames) >
                self.conn.params.max_header_size):
            if self.conn.is_client:
                # TODO: Need tests for client side of headers-too-large.
                # What's the best way to send an error?
                self.delegate.on_connection_close()
            else:
                # write_headers needs a start line so it can tell
                # whether this is a HEAD or not. If we're rejecting
                # the headers we can't know so just make something up.
                # Note that this means the error response body MUST be
                # zero bytes so it doesn't matter whether the client
                # sent a HEAD or a GET.
                self._request_start_line = RequestStartLine('GET', '/', 'HTTP/2.0')
                start_line = ResponseStartLine('HTTP/2.0', 431, 'Headers too large')
                self.write_headers(start_line, HTTPHeaders())
                self.finish()
            return 
開發者ID:bdarnell,項目名稱:tornado_http2,代碼行數:21,代碼來源:stream.py

示例6: __call__

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def __call__(self, request):
        data = {}
        response = []

        def start_response(status, response_headers, exc_info=None):
            data["status"] = status
            data["headers"] = response_headers
            return response.append
        app_response = self.wsgi_application(
            WSGIContainer.environ(request), start_response)
        try:
            response.extend(app_response)
            body = b"".join(response)
        finally:
            if hasattr(app_response, "close"):
                app_response.close()
        if not data:
            raise Exception("WSGI app did not call start_response")

        status_code, reason = data["status"].split(' ', 1)
        status_code = int(status_code)
        headers = data["headers"]
        header_set = set(k.lower() for (k, v) in headers)
        body = escape.utf8(body)
        if status_code != 304:
            if "content-length" not in header_set:
                headers.append(("Content-Length", str(len(body))))
            if "content-type" not in header_set:
                headers.append(("Content-Type", "text/html; charset=UTF-8"))
        if "server" not in header_set:
            headers.append(("Server", "TornadoServer/%s" % tornado.version))

        start_line = httputil.ResponseStartLine("HTTP/1.1", status_code, reason)
        header_obj = httputil.HTTPHeaders()
        for key, value in headers:
            header_obj.add(key, value)
        request.connection.write_headers(start_line, header_obj, chunk=body)
        request.connection.finish()
        self._log(status_code, request) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:41,代碼來源:wsgi.py

示例7: respond_100

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def respond_100(self, request):
        self.http1 = request.version.startswith('HTTP/1.')
        if not self.http1:
            request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
                                             HTTPHeaders())
            request.connection.finish()
            return
        self.request = request
        self.request.connection.stream.write(
            b"HTTP/1.1 100 CONTINUE\r\n\r\n",
            self.respond_200) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:13,代碼來源:simple_httpclient_test.py

示例8: headers_received

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def headers_received(
        self,
        start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
        headers: httputil.HTTPHeaders,
    ) -> Optional[Awaitable[None]]:
        if self.stream_request_body:
            self.request._body_future = Future()
            return self.execute()
        return None 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:11,代碼來源:web.py

示例9: headers_received

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def headers_received(
        self,
        start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
        headers: httputil.HTTPHeaders,
    ) -> Optional[Awaitable[None]]:
        self.request = httputil.HTTPServerRequest(
            connection=self.connection,
            start_line=typing.cast(httputil.RequestStartLine, start_line),
            headers=headers,
        )
        return None 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:13,代碼來源:httpserver.py

示例10: finish

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def finish(self) -> None:
        self.connection.write_headers(
            httputil.ResponseStartLine("HTTP/1.1", 404, "Not Found"),
            httputil.HTTPHeaders(),
        )
        self.connection.finish()


# _RuleList can either contain pre-constructed Rules or a sequence of
# arguments to be passed to the Rule constructor. 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:routing.py

示例11: headers_received

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def headers_received(
        self,
        start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
        headers: httputil.HTTPHeaders,
    ) -> Optional[Awaitable[None]]:
        if headers.get("Content-Encoding") == "gzip":
            self._decompressor = GzipDecompressor()
            # Downstream delegates will only see uncompressed data,
            # so rename the content-encoding header.
            # (but note that curl_httpclient doesn't do this).
            headers.add("X-Consumed-Content-Encoding", headers["Content-Encoding"])
            del headers["Content-Encoding"]
        return self._delegate.headers_received(start_line, headers) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:15,代碼來源:http1connection.py

示例12: finish

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def finish(self):
        self.connection.write_headers(
            httputil.ResponseStartLine("HTTP/1.1", 404, "Not Found"), httputil.HTTPHeaders())
        self.connection.finish() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:6,代碼來源:routing.py

示例13: respond_100

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def respond_100(self, request):
        self.http1 = request.version.startswith('HTTP/1.')
        if not self.http1:
            request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
                                             HTTPHeaders())
            request.connection.finish()
            return
        self.request = request
        fut = self.request.connection.stream.write(
            b"HTTP/1.1 100 CONTINUE\r\n\r\n")
        fut.add_done_callback(self.respond_200) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:13,代碼來源:simple_httpclient_test.py

示例14: headers_received

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import ResponseStartLine [as 別名]
def headers_received(
        self,
        start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
        headers: httputil.HTTPHeaders,
    ) -> None:
        assert isinstance(start_line, httputil.ResponseStartLine)
        if start_line.code != 101:
            await super(WebSocketClientConnection, self).headers_received(
                start_line, headers
            )
            return

        if self._timeout is not None:
            self.io_loop.remove_timeout(self._timeout)
            self._timeout = None

        self.headers = headers
        self.protocol = self.get_websocket_protocol()
        self.protocol._process_server_headers(self.key, self.headers)
        self.protocol.stream = self.connection.detach()

        IOLoop.current().add_callback(self.protocol._receive_frame_loop)
        self.protocol.start_pinging()

        # Once we've taken over the connection, clear the final callback
        # we set on the http request.  This deactivates the error handling
        # in simple_httpclient that would otherwise interfere with our
        # ability to see exceptions.
        self.final_callback = None  # type: ignore

        future_set_result_unless_cancelled(self.connect_future, self) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:33,代碼來源:websocket.py


注:本文中的tornado.httputil.ResponseStartLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。