模块概述篇3--tornado.httpserver

概述:
非阻塞单线程http服务(A non-blocking, single-threaded HTTP server),在进程之初开启服务后,和application没有任何直接的互相影响。

1、

class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate)

HTTPServer是TCPServer的子类,关于socket连接的部分由TCPServer类实现,HTTPServer只用于实现1.处理连接(connection),2.生成请求(request)。
# in class HTTPServer
# 1.处理连接
def handle_stream(self, stream, address):
context = _HTTPRequestContext(stream, address, self.protocol)//生成请求上下文
conn = HTTP1ServerConnection(stream, self.conn_params, context) //生成请求
self._connections.add(conn) //加入到连接池,请求结束还要移除
conn.start_serving(self)//该连接开始服务
# 2.生成请求
def start_request(self, server_conn, request_conn): //开始处理请求
return _ServerRequestAdapter(self, server_conn, request_conn) //交由_ServerRequestAdapter生成request

2、

class _HTTPRequestContext(object)
#从socket(stream,address protocol)请抽出上下文
#协议族(address_family = stream.socket.family)
#请求地址(remote_ip = address[0])
#协议
# isinstance(stream, iostream.SSLIOStream): 
#   self.protocol = "https"
# else:  
#   self.protocol = "http"

3、

class _ServerRequestAdapter(httputil.HTTPMessageDelegate)
//待完善

你可能感兴趣的:(模块概述篇3--tornado.httpserver)