Tornado Study Notes Tornado framework analysis

Source: Internet
Author: User

19.1 HTTP Server request processing flowchart

(1) Call Httpserver bind method, bind socket's listening port number;

(2) Call Httpserver's Listen method, initialize a listen socket object;

(3) Call the Add_hander method to add the initialized listen socket object to the Ioloop pool, at which point the socket begins to listen for requests from the client.

(4) The client sends an HTTP request;

(5) Listen socket to hear the client's request, call the listen socket's accept method, to start receiving requests, while regenerating a new socket, in order to differentiate, called the client socket.

(6) The Handle_stream method of Ioloop callback Httpserver;

(7) Handle_stream initializes the Http1serverconnection object and adds it to the pool;

(8) Call Http1serverconnection's Start_serve method, start processing the request, initialize the iostream, Http1connection object, and initialize the _requestdispater request dispatcher.

(9) _requestdispater the request dispatcher initializes the Httpserverrequest object, set the Hanlder_class and Handler_kwargs properties according to the mapping of the application configuration.

Http1connection reads the requested information, such as the request header, the request body, and so on.

(11) Parse the read request header, the request body data block information, for the custom RequestHandler call.

(12) Call the relevant methods of the custom RequestHandler, such as GET, post.

(13) Return the result of the processing (usually the requesthandler of the Render method) to the http1connection;

Http1connection writes the response to the iostream stream;

() The client socket returns the stream to the clients.

Class 19.2 Diagram

which

Httpserverconnectiondelegate, Httpmessagedelegate is the interface. IOStream, Ioloop, Application, Httpserver, RequestHandler, httpserverrequest are the more important modules in tornado. However, application developers generally only customize settings and development for application, RequestHandler, especially RequestHandler. A typical Torando application site consists of application, Httpserver, and a sequence of requesthandler.

19.3 RequestHandler Process

(1) Initialize the RequestHandler object first;

(2) Call the custom Initialize method, and carry out related initialization operations, such as database connection, initialization of various variables, etc.

(3) According to the type of HTTP request, determine whether to support the request, RequestHandler default supported methods include GET, POST, HEAD, DELETE, PATCH, PUT, OPTIONS;

(4) If supported, call the Prepare method. If not supported, end the process;

(5) Determine whether the prepare method sets the finished property to True, if it is, end the process, and if not, move to the next step.

(6) Call the corresponding method, such as Get, post;

(7) Call the Write or Render method;

(8) Determine if the finished property is set to True, if it is, end the process, and if not, go to the next step.

(9) Call the Finish method to write the data to the return stream.

(10) Finally call the On_finish method to release the associated resource or variable.

Tornado Study Notes Tornado framework analysis

Related Article

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.