概述:
非阻塞單線程http服務(wù)(A non-blocking, single-threaded HTTP server)礼华,在進(jìn)程之初開(kāi)啟服務(wù)后拗秘,和application沒(méi)有任何直接的互相影響。
1雕旨、
class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate)
HTTPServer是TCPServer的子類,關(guān)于socket連接的部分由TCPServer類實(shí)現(xiàn)凡涩,HTTPServer只用于實(shí)現(xiàn)1.處理連接(connection)棒搜,2.生成請(qǐng)求(request)。
# in class HTTPServer
# 1.處理連接
def handle_stream(self, stream, address):
context = _HTTPRequestContext(stream, address, self.protocol)//生成請(qǐng)求上下文
conn = HTTP1ServerConnection(stream, self.conn_params, context) //生成請(qǐng)求
self._connections.add(conn) //加入到連接池活箕,請(qǐng)求結(jié)束還要移除
conn.start_serving(self)//該連接開(kāi)始服務(wù)
# 2.生成請(qǐng)求
def start_request(self, server_conn, request_conn): //開(kāi)始處理請(qǐng)求
return _ServerRequestAdapter(self, server_conn, request_conn) //交由_ServerRequestAdapter生成request
2力麸、
class _HTTPRequestContext(object)
#從socket(stream,address protocol)請(qǐng)抽出上下文
#協(xié)議族(address_family = stream.socket.family)
#請(qǐng)求地址(remote_ip = address[0])
#協(xié)議
# isinstance(stream, iostream.SSLIOStream):
# self.protocol = "https"
# else:
# self.protocol = "http"
3讹蘑、
class _ServerRequestAdapter(httputil.HTTPMessageDelegate)
//待完善