概述:本模塊是對HTTP/1.x協(xié)議實(shí)現(xiàn)的客戶端和服務(wù)端
1厨钻、
#本類是用來處理網(wǎng)絡(luò)“請求”數(shù)據(jù)的調(diào)度類
#想要學(xué)習(xí)實(shí)現(xiàn)一個(gè)http協(xié)議解析器本類是重點(diǎn)
#tornado中將作為server端收到的請求和client發(fā)出請求統(tǒng)一抽象為本類寡具,已is_client來區(qū)分
#client模式由asyncclient創(chuàng)建
#server端由HTTP1ServerConnection作為構(gòu)建類創(chuàng)建
class HTTP1Connection(httputil.HTTPConnection)
//核心方法
def _read_message(self, delegate)
#1. 通過_parse_headers解析start_line, headers(httputil.HTTPHeaders.parse方法)所禀。本方法描述了http報(bào)文頭的規(guī)則肴颊。
#2. delegate.headers_received(start_line, headers)將header傳遞給Application,創(chuàng)建響應(yīng)的handler迎变,查看是否有必要解析body
#server模式傳遞順序:_ServerRequestAdapter.headers_received-->(Application)_RequestDispatcher.headers_received-->_RequestDispatcher.execute(參見tornado.web模塊篇)
#client模式待續(xù)
#3. _read_body將body傳遞給handler宁仔。
#傳遞順序:_read_body-->_read_fixed_body->_RequestDispatcher.data_received->handler.data_received
#等待handler _write_finished收尾