Skip to content

HTTP Protocol

HyperText Transfer Protocol(超文本传送协议)

client/server model

  • client: browser that requests, receives and "displays" the web objects
  • server: web server sends web objects in response to requests

transport protocol - TCP
HTTP 1.0 - RFC 1945
HTTP 1.1 - RFC 2068
Port - 80

Distingulish

HTTP 1.0HTTP 1.1
a TCP tranmit one objectTCP transmit multiple objects

Stateless

server maintains no information about past client requests

  • Non-persistent
    • HTTP/1.0
    • server parses requests, responses, and close TCP connections
    • 2 RTTs(Round Trip Time) to fetch each object
    • slow start for each object transfer
  • Persistent
  • default for HTTP/1.1
  • on same TCP connection(see as above)
  • client sends requests for all referenced objects as soon as it receives base HTML
  • Fewer RTTs
  • Less slow start

HTTP message format

  • Request
    • request line

      method URL version

      • method
        methodintroductionusage
        GETRequests a representation of the specified resourceonly retrieves data
        HEADAsks for a response identical to a GET request, but without the response bodyoften retrieves the meta information of resource
        POSTSubmits an entity to the specified resourceoften causes a change in state or side effects on the server
        PUTReplaces all current representations of the target resource with the request payloadoften updates the resource that existed or provides new resource
        DELETEDeletes the specified resourcedeletes resource
        CONNECTEstablishes a tunnel to the server identified by the target resourceoften for proxy servers
        OPTIONSDescribes the communication options for the target resourcerequests for available options
        TRACEPerforms a message loop-back test along the path to the target resourceoften for tests and diagnoses
        PATCHApplies partial modifications to a resourceoften for tests and diagnoses
      • version
        version
        HTTP/1.0
        HTTP/1.1
        HTTP/2.0
    • header lines(multiple lines formatted the same as below)

      header field name:value
      header field name:value
      ...

      • header field name
        header field nameintroduction
        AcceptInforms the server about the types of data that can be sent back
        Accept-EncodingThe encoding algorithm, usually a compression algorithm, that can be used on the resource sent back
        Accept-LanguageInforms the server about the human language the server is expected to send back
        ConnectionControls whether the network connection stays open after the current transaction finishes
        HostSpecifies the domain name of the server (for virtual hosting), and (optionally) the TCP port number on which the server is listening
        RefererThe address of the previous web page from which a link to the currently requested page was followed
        User-AgentContains a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent
        CookieContains stored HTTP cookies previously sent by the server with the Set-Cookie header
        Cache-ControlDirectives for caching mechanisms in both requests and responses
    • extra carriage return and line feed
    • Entity body

      data here......

  • Response
    • status line

      version status_code status_description

      • status codes

        status code classintroduction
        1xxInformational responses
        2xxSuccessful responses
        3xxRedirection messages
        4xxClient error responses
        5xxServer error responses
        status codedescription
        100Continue
        101Switching Protocols
        200OK 😃
        202Accepted
        204No Content
        205Reset Content
        206Partial Content
        301Moved Permanently 😦
        302Found
        304Not Modified
        307Temporary Redirect
        308Permanent Redirect
        400Bad Request
        403Forbidden 😦
        404Not Found 😦
        405Method Not Allowed
        406Not Acceptable
        500Internal Server Error
        501Not Implemented
        502Bad Gateway
        505HTTP Version Not Supported
    • header lines(multiple lines formatted the same as below)

      header field name:value
      header field name:value
      ...

      • header field name
        header field nameintroduction
        DateContains the date and time at which the message was originated
        Content-TypeIndicates the media type of the resource
        Content-LengthThe size of the resource, in decimal number of bytes
        Content-EncodingUsed to specify the compression algorithm
        Last-ModifiedThe last modification date of the resource, used to compare several versions of the same resource
        Set-CookieSend cookies from the server to the user-agent
    • extra carriage return and line feed
    • data

      data here...

Web Caches

satisfy client request without involving origin server

  • web accesses via web cache
  • client sends all http requests to web cache
    • If objects at web cache, web cache immediately returns the objects in http response
    • Else requests objects from the origin server, then returns http response to client
  • Advantages
    • smaller response time
    • decrease traffic to distant servers