(Tornado Source Analysis _004) HTTP Server processing the parsed HTTP data

Source: Internet
Author: User

The HTTP server in tornado is a connecting link, It reads and resolves HTTP messages from the socket via tornado.http1connection.HTTP1ServerConnection and tornado.http1connection.HTTP1Connection

The application is then called to process the parsed HTTP message by passing the application as the data processing class to the two read data classes

The specific code is as follows

#Common Torando Start-up methodsApplication =tornado.web.Application (Handlers) Application.listen (8888) classApplication (reversiblerouter):defListen (self):#Create Httpserver at startup         fromTornado.httpserverImportHttpserver Server= Httpserver (Self, * *Kwargs) Server.listen (port, address)returnServerclassHttpserver (Tcpserver,configurable,httputil. Httpserverconnectiondelegate):def __init__(self, application):#wrap the application into _callableadapter, as application is responsible for processing the complete request,Self.delegate =_callableadapter (application)classhttp1connection (Httputil. Httpconnection):defRead_response (Self, delegate):ifself.params.decompress:delegate=_gzipmessagedelegate (delegate, Self.params.chunk_size)returnSelf._read_message (delegate)def_read_message (Self, delegate):#call the upper layer that httpserver processing the parsed HTTP message header, the processing is also asynchronousdelegate.headers_received (start_line, headers)def_read_body (self, Code, headers, delegate):#body may be larger, when the Shard arrivesdelegate.data_received (Chunk)class_callableadapter (Httputil. Httpmessagedelegate):def __init__(self, Request_callback, request_conn): Self.connection=Request_conn Self.request_callback=Request_callback self.request=None self.delegate=None self._chunks= []    defheaders_received (self, Start_line, headers):#contemporary with this function, the description is a new request to createSelf.request =Httputil. Httpserverrequest (Connection=self.connection, start_line=Start_line, headers=headers)defdata_received (self, chunk):#body is the Shard arrives, saved for final assemblyself._chunks.append (Chunk)defFinish (self):#Assemble bodySelf.request.body = b"'. Join (Self._chunks) self.request._parse_body ()#Call Application (Tornado Web framework) to process requestSelf.request_callback (self.request)defOn_connection_close (self): Self._chunks= None

(Tornado Source Analysis _004) HTTP Server processing the parsed HTTP data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.