Talk about the HTTP protocol

Source: Internet
Author: User
Tags server memory nginx reverse proxy

HTTP protocol

  1. Summary: Hyper text Transfer Protocol (Hypertext Transfer Protocol) is an abbreviation for transferring hypertext to a local browser from the World Wide Web (www:world Wide Web) server.

  2. The HTTP protocol belongs to the application layer, which transmits data based on TCP/IP protocol.

  3. The HTTP protocol works on the client-server architecture, and the browser sends all requests to the HTTP server as an HTTP client through a URL, and the server then processes the request and returns the corresponding response information.

  4. Three features of the HTTP protocol:

    • No connection: Restrict each connection to process only one request, when the server finishes processing the customer request and return the response, immediately disconnect (similar to short connection), so as to save the transmission time, http/1.0 default is short connection and http/1.1 after the default is long even packet header will have keepalive, Server-side need to turn on support.

    • Media independence: As long as the client and server side know how to handle the data content, any data type can be sent over HTTP, specifying the appropriate content type.

    • Stateless: There is no memory function for transaction processing, which means that the subsequent processing needs to be re-transmitted prior to the information, in order to maintain the session, we use a cookie and session to maintain the conversational mechanism.

  5. Working principle:

  6. HTTP long connection/short connection: In fact, the TCP/IP transport layer is a long connection and short connection;

    Long connection: After both ends of the data transfer, the TCP connection is kept constant, waiting for the same domain name to be reused for the channel to transmit data.

    Short connection: After the data transfer is complete, the TCP connection is disconnected directly, and the next time you need to establish a new connection to transfer data.

    The pros and cons: long connections can bring higher TPS than short connections (processing messages per second, throughput), lower CPU consumption, less IO, higher memory footprint, fewer system calls

    • Apache can perform stress tests in prefork mode using AB.

      • See also Web server long connection

  7. Long-connected usage scenarios and web_server-related configurations

    • Under what circumstances should we use long connections:

      • With sufficient server memory, KeepAlive on or off has little effect on system performance.

      • If the static resources on the server (HTML, JS, CSS, picture files) are mostly, it is recommended to open keepalive.

      • If the server is more dynamic requests (more database connections, more access to the file system), KeepAlive off, will save a certain amount of memory, the saved memory can be used as file system cache, reduce I/O pressure.

    • Web_server Long Connection configuration:

      • Apache:

         
        //httpd.conf Reference this extension file, the default does not refer to
        Span class= "cm-comment" > #Include conf/extra/httpd-default.conf
        //Edit httpd-default.conf file Partial parameters list
        //time-out after request and before response
        timeout 300
        //on or off KeepAlive
        keepalive on
        //allow the maximum number of long connection requests
        maxkeepaliverequests 100
        //wait for next connection from same client, hold time setting
        keepalivetimeout 5
      • Nginx:nginx Reverse proxy for long connection

  8. Message structure

    • Client Request message Format:

      • Request Header (header)

      • Request Line

      • Blank Line

      • Request data

    • Server Response message Format:

      • Status line

      • Message header

      • Blank Line

      • Response body

    • Common methods

      method description contains the topic
      GET Get a copy of a document from the server Whether
      POST Send data to the server that needs to be processed Is
      PUT Store the requested subject section on the server Is
      DELETE Delete a document from the server Whether
    • How get and Post requests compare

      • GET: Requests data from the specified resource.

      • Attention:

          • GET Request can be cached

          • GET Request remains in browser history

          • GET Request can be bookmarked

          • GET The request should not be processed with sensitive data using the

          • GET Request has a length limit

          • GET Request should only be used to retrieve data

          • The parameter passed by the GET request is in the of the request URL? after & character concatenation and visible in the address bar

      • POST: Submits the data to be processed to the specified resource

      • Attention:

        • POST requests are not cached

        • POST requests are not persisted in browser history

        • POST cannot be bookmarked

        • POST request has no requirement for data length

Talk about the HTTP protocol

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.