Brief http service

Description of the http protocol

  1. Protocol Version
    (1) http / 0.9: a prototype version, features simple, only one command GET. GET /index.html, the server can only respond HTML format string, can not respond to other formats
    (2) http / 1.0: support for cache, MIME, method, each TCP connection only send a request to send data is completed, the connection Close, but also if the requested additional resources, it is necessary to re-create a new connection; introduced hEAD command and POST command; ACII codes header information is followed by data in any format may be
    http (3) / 1.1: introducing a persistent connection, i.e. TCP default connection is not closed, multiple requests can be multiplexed without declaration connection: keep-alive; pipeline mechanism is introduced, i.e., in the same TCP connection, the client may send multiple requests at the same time, to further improve the efficiency of the HTTP protocol; new method: the PUT, the PATCH, the OPTIONS, the DELETE
    (. 4) HTTP / 2.0: header and body are binary data, referred to as header information and data frames, multiplexed TCP connection, in a connection, the client and browsing device can send or respond to multiple requests simultaneously, and do not correspond in order to avoid the "team head clogging," this two-way real-time communication is called multiplexing. Introducing header compression mechanism, header compression using gzip or compress before sending; the client and the server at the same time maintaining a table header, all fields will be stored in this table, to generate an index number, do not send the same field, only send index No. improve the speed. Unsolicited allows the server to take the initiative to send resources to the client, that server push.
  2. HTTP mechanism
    (1) mechanism:
    http request: Request http
    http response: http response
    once the transaction http: Request <-> Response
    (2) web resource: web resource
    a web page consists of a plurality of resources, open a page, it will there are more resources out of the show, but must be requested separately for each resource. Therefore, a "web page" is usually not a single resource, but a set collection
    of static files: no need to make an extra server processing
    file suffix: .html, .txt, .jpg, .js , .css, .mps, .avi
    dynamic files: the server program execution, execution returns the result
    file suffix: .php, .jsp, .asp
    (. 3) to improve the performance of HTTP connections
    are connected in parallel: concurrent TCP connections through a plurality of HTTP requests
    persistent connection: keep-alive , long connection reuse TCP connection, and the connection closed in order to eliminate the delay, and the number of time to determine whether the transaction to close the connecting
    duct switched connection: the connection initiation of concurrent TCP HTTP requests through a shared
    multiplexed connections: transmission request alternate and response packets (experimental)
  3. URL组成
    URL:shceme://username:password@host:port/path;params?query#frag
     shceme:方案,访问服务器以获取资源时要使用哪种协议
     user:用户,某些方案访问资源时需要的用户名
     password:密码,用户对应的密码,中间用:分隔
     host:主机,资源宿主服务器的主机名或IP地址
     port:端口,资源宿主服务器正在监听的端口号,很多方案有默认端口号
     path:路径,服务器资源的本机名,由一个/将其与前面的URL组件分隔
     params:参数,指定输入的参数,参数为名/值对,多个参数,用;分隔
     query:查询,传递参数给程序,如数据库,用?分隔,多个查询用&分隔
     frag:片段,一个片或一部分资源的名字,此组件在客户端使用,用#分隔
  4. A complete http request processing
    (1) to establish a connection: accept or reject the connection request
    (2) receiving a request: receiving a client request message a request for a resource during
    web access response model (web I / O)
    single process I / O model: start a process to handle user requests, and process only a plurality of serially in response to a request
    multi-process I / O model: start a plurality of parallel processes, each process in response to a connection request
    multiplexed I / O structure: start a process, while responding to the N connection requests
    method: multithreaded model and event-driven
    multi-threaded model: a process generating N threads, each thread in response to a connection request
    event-driven: a process process N requests
    multiplexed multi-process I / O model: M start of processes, each process in response to N connection requests, while receiving requests of M * N
    (3) processing request: server parses the request message, and acquires the resource request and the request method and other related information, according to methods, resources, optional header and a body portion processes the request
    HTTP request conventional manner `.Method ':
    the GET, the POST, the hEAD, the PUT, the DELETE, the TRACE, the OPTIONS
    (. 4) to access the resource:
    Service Gets a resource web server request message requests that the server storing web resources, is responsible for providing a static resource request of the other party to the requestor, or dynamically generated resources after running
    a web server resource path mapping manner:
    (A) docroot
    (B) Alias
    (C) Hosting the docroot
    (D) a user's home directory the docroot
    5. The constructed response packet:
    Once the web server identification from resources on the implementation of the operation method described in the request, and returns a response packet.
    Response message includes response status code, the response header, if the generated response body, then, further comprising in response to the body
    (1) http protocol common status code
    200: success, the request data in response entity-body portion of the packet; the OK
    301: URL pointing to resource request has been deleted; but in the response message text indicates the new location of the resource now live by the head location; Moved Permanently
    302: response message location indication of provisional new location of the resource Moved temporarily the
    304: client issued condition requests, but resources on the server has not changed, the response to the response status code via a client; Not Modified
    401: need to enter the account number and password authentication can access the resource; Unauthorized the
    403: request is prohibited; Foibidden
    404: the server can not find the resources requested by the client; not found
    500: internal server error; internal server error
    502: the proxy server receives a response from the pseudo back-end server, if you can not connect to the gateway; Bad gateway
    503: service unavailable temporary server maintenance or overloaded server to process the request
    504: gateway timeout
    (2) in response to the body: If the transaction had a response body, it will be content in the response packet sent back expired. Response packet generally comprises:
    describes the MIME type of the response body Content-Type header
    describes the length of the body in response Content-Length
    body actual contents of the packet
    (3) URL redirection:
    The web service response is not to build the resource requested by the client, but in addition a resource access path
    (4) MIME type:
    Web server is responsible for determining the response MIME type of the body. Various methods configuration server may manage resource and MIME types
    6 sends a response message
    7 log
    Finally, when the end of the transaction, web server adds an entry in the log file, the transaction has been performed will be described

Guess you like

Origin blog.51cto.com/14418331/2443978