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


Python httputil._encode_header方法代碼示例

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


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

示例1: _accept_connection

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import _encode_header [as 別名]
def _accept_connection(self):
        subprotocol_header = ''
        subprotocols = self.request.headers.get("Sec-WebSocket-Protocol", '')
        subprotocols = [s.strip() for s in subprotocols.split(',')]
        if subprotocols:
            selected = self.handler.select_subprotocol(subprotocols)
            if selected:
                assert selected in subprotocols
                subprotocol_header = ("Sec-WebSocket-Protocol: %s\r\n"
                                      % selected)

        extension_header = ''
        extensions = self._parse_extensions_header(self.request.headers)
        for ext in extensions:
            if (ext[0] == 'permessage-deflate' and
                    self._compression_options is not None):
                # TODO: negotiate parameters if compression_options
                # specifies limits.
                self._create_compressors('server', ext[1])
                if ('client_max_window_bits' in ext[1] and
                        ext[1]['client_max_window_bits'] is None):
                    # Don't echo an offered client_max_window_bits
                    # parameter with no value.
                    del ext[1]['client_max_window_bits']
                extension_header = ('Sec-WebSocket-Extensions: %s\r\n' %
                                    httputil._encode_header(
                                        'permessage-deflate', ext[1]))
                break

        if self.stream.closed():
            self._abort()
            return
        self.stream.write(tornado.escape.utf8(
            "HTTP/1.1 101 Switching Protocols\r\n"
            "Upgrade: websocket\r\n"
            "Connection: Upgrade\r\n"
            "Sec-WebSocket-Accept: %s\r\n"
            "%s%s"
            "\r\n" % (self._challenge_response(),
                      subprotocol_header, extension_header)))

        self._run_callback(self.handler.open, *self.handler.open_args,
                           **self.handler.open_kwargs)
        self._receive_frame() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:46,代碼來源:websocket.py

示例2: _accept_connection

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import _encode_header [as 別名]
def _accept_connection(self, handler: WebSocketHandler) -> None:
        subprotocol_header = handler.request.headers.get("Sec-WebSocket-Protocol")
        if subprotocol_header:
            subprotocols = [s.strip() for s in subprotocol_header.split(",")]
        else:
            subprotocols = []
        self.selected_subprotocol = handler.select_subprotocol(subprotocols)
        if self.selected_subprotocol:
            assert self.selected_subprotocol in subprotocols
            handler.set_header("Sec-WebSocket-Protocol", self.selected_subprotocol)

        extensions = self._parse_extensions_header(handler.request.headers)
        for ext in extensions:
            if ext[0] == "permessage-deflate" and self._compression_options is not None:
                # TODO: negotiate parameters if compression_options
                # specifies limits.
                self._create_compressors("server", ext[1], self._compression_options)
                if (
                    "client_max_window_bits" in ext[1]
                    and ext[1]["client_max_window_bits"] is None
                ):
                    # Don't echo an offered client_max_window_bits
                    # parameter with no value.
                    del ext[1]["client_max_window_bits"]
                handler.set_header(
                    "Sec-WebSocket-Extensions",
                    httputil._encode_header("permessage-deflate", ext[1]),
                )
                break

        handler.clear_header("Content-Type")
        handler.set_status(101)
        handler.set_header("Upgrade", "websocket")
        handler.set_header("Connection", "Upgrade")
        handler.set_header("Sec-WebSocket-Accept", self._challenge_response(handler))
        handler.finish()

        self.stream = handler._detach_stream()

        self.start_pinging()
        try:
            open_result = handler.open(*handler.open_args, **handler.open_kwargs)
            if open_result is not None:
                await open_result
        except Exception:
            handler.log_exception(*sys.exc_info())
            self._abort()
            return

        await self._receive_frame_loop() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:52,代碼來源:websocket.py

示例3: _accept_connection

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import _encode_header [as 別名]
def _accept_connection(self):
        subprotocol_header = self.request.headers.get("Sec-WebSocket-Protocol")
        if subprotocol_header:
            subprotocols = [s.strip() for s in subprotocol_header.split(',')]
        else:
            subprotocols = []
        self.selected_subprotocol = self.handler.select_subprotocol(subprotocols)
        if self.selected_subprotocol:
            assert self.selected_subprotocol in subprotocols
            self.handler.set_header("Sec-WebSocket-Protocol", self.selected_subprotocol)

        extensions = self._parse_extensions_header(self.request.headers)
        for ext in extensions:
            if (ext[0] == 'permessage-deflate' and
                    self._compression_options is not None):
                # TODO: negotiate parameters if compression_options
                # specifies limits.
                self._create_compressors('server', ext[1], self._compression_options)
                if ('client_max_window_bits' in ext[1] and
                        ext[1]['client_max_window_bits'] is None):
                    # Don't echo an offered client_max_window_bits
                    # parameter with no value.
                    del ext[1]['client_max_window_bits']
                self.handler.set_header("Sec-WebSocket-Extensions",
                                        httputil._encode_header(
                                            'permessage-deflate', ext[1]))
                break

        self.handler.clear_header("Content-Type")
        self.handler.set_status(101)
        self.handler.set_header("Upgrade", "websocket")
        self.handler.set_header("Connection", "Upgrade")
        self.handler.set_header("Sec-WebSocket-Accept", self._challenge_response())
        self.handler.finish()

        self.handler._attach_stream()
        self.stream = self.handler.stream

        self.start_pinging()
        open_result = self._run_callback(self.handler.open, *self.handler.open_args,
                                         **self.handler.open_kwargs)
        if open_result is not None:
            yield open_result
        yield self._receive_frame_loop() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:46,代碼來源:websocket.py


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