HTTP Messages - HTTP | MDN (2024)

HTTP messages are how data is exchanged between a server and a client. There are two types of messages: requests sent by the client to trigger an action on the server, and responses, the answer from the server.

Web developers, or webmasters, rarely craft these textual HTTP messages themselves: software, a Web browser, proxy, or Web server, perform this action. They provide HTTP messages through config files (for proxies or servers), APIs (for browsers), or other interfaces.

HTTP Messages - HTTP | MDN (1)

HTTP requests, and responses, share similar structure and are composed of:

  1. A start-line describing the requests to be implemented, or its status of whether successful or a failure. This is always a single line.
  2. An optional set of HTTP headers specifying the request, or describing the body included in the message.
  3. A blank line indicating all meta-information for the request has been sent.
  4. An optional body containing data associated with the request (like content of an HTML form), or the document associated with a response. The presence of the body and its size is specified by the start-line and HTTP headers.

The start-line and HTTP headers of the HTTP message are collectively known as the head of the requests, and the part afterwards that contains its content is known as the body.

HTTP Messages - HTTP | MDN (2)

HTTP Requests

Request line

Note: The start-line is called the "request-line" in requests.

HTTP requests are messages sent by the client to initiate an action on the server. Their request-line contain three elements:

  1. An HTTP method, a verb (like GET, PUT or POST) or a noun (like HEAD or OPTIONS), that describes the action to be performed. For example, GET indicates that a resource should be fetched or POST means that data is pushed to the server (creating or modifying a resource, or generating a temporary document to send back).
  2. The request target, usually a URL, or the absolute path of the protocol, port, and domain are usually characterized by the request context. The format of this request target varies between different HTTP methods. It can be
    • An absolute path, ultimately followed by a '?' and query string. This is the most common form, known as the origin form, and is used with GET, POST, HEAD, and OPTIONS methods.
      • POST / HTTP/1.1
      • GET /background.png HTTP/1.0
      • HEAD /test.html?query=alibaba HTTP/1.1
      • OPTIONS /anypage.html HTTP/1.0
    • A complete URL, known as the absolute form, is mostly used with GET when connected to a proxy. GET https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages HTTP/1.1
    • The authority component of a URL, consisting of the domain name and optionally the port (prefixed by a ':'), is called the authority form. It is only used with CONNECT when setting up an HTTP tunnel. CONNECT developer.mozilla.org:80 HTTP/1.1
    • The asterisk form, a simple asterisk ('*') is used with OPTIONS, representing the server as a whole. OPTIONS * HTTP/1.1
  3. The HTTP version, which defines the structure of the remaining message, acting as an indicator of the expected version to use for the response.

Headers

HTTP headers from a request follow the same basic structure of an HTTP header: a case-insensitive string followed by a colon (':') and a value whose structure depends upon the header. The whole header, including the value, consists of one single line, which can be quite long.

Many different headers can appear in requests. They can be divided in several groups:

  • General headers, like Via, apply to the message as a whole.
  • Request headers, like User-Agent or Accept, modify the request by specifying it further (like Accept-Language), by giving context (like Referer), or by conditionally restricting it (like If-None-Match).
  • Representation headers like Content-Type that describe the original format of the message data and any encoding applied (only present if the message has a body).

HTTP Messages - HTTP | MDN (3)

Body

The last part of a response is the body. Not all responses have one: responses with a status code that sufficiently answers the request without the need to include message content (like 201 Created or 204 No Content) usually don't.

Bodies can be broadly divided into two categories:

  • Single-resource bodies, consisting of one single file, defined by the two headers: Content-Type and Content-Length.
  • Multiple-resource bodies, consisting of a multipart body, each containing a different bit of information. This is typically associated with HTML Forms.

HTTP Responses

Status line

Note: The start-line is called the "status line" in responses.

The start line of an HTTP response, called the status line, contains the following information:

  1. The protocol version, usually HTTP/1.1, but can also be HTTP/1.0.
  2. A status code, indicating success or failure of the request. Common status codes are 200, 404, or 302.
  3. A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.

A typical status line looks like: HTTP/1.1 404 Not Found.

Headers

HTTP headers for responses follow the same structure as any other header: a case-insensitive string followed by a colon (':') and a value whose structure depends upon the type of the header. The whole header, including its value, presents as a single line.

Many different headers can appear in responses. These can be divided into several groups:

  • General headers, like Via, apply to the whole message.
  • Response headers, like Vary and Accept-Ranges, give additional information about the server which doesn't fit in the status line.
  • Representation headers like Content-Type that describe the original format of the message data and any encoding applied (only present if the message has a body).

HTTP Messages - HTTP | MDN (4)

Body

The last part of a response is the body. Not all responses have one: responses with a status code that sufficiently answers the request without the need to include content (like 201 Created or 204 No Content) usually don't.

Bodies can be broadly divided into three categories:

  • Single-resource bodies, consisting of a single file of known length, defined by the two headers: Content-Type and Content-Length.
  • Single-resource bodies, consisting of a single file of unknown length, encoded by chunks with Transfer-Encoding set to chunked.
  • Multiple-resource bodies, consisting of a multipart body, each containing a different section of information. These are relatively rare.

HTTP/2 Frames

HTTP/1.x messages have a few drawbacks for performance:

  • Headers, unlike bodies, are uncompressed.
  • Headers are often very similar from one message to the next one, yet still repeated across connections.
  • Although HTTP/1.1 has pipelining, it's not activated by default in most browsers, and doesn't allow for multiplexing (i.e. sending requests concurrently). Several connections need opening on the same server to send requests concurrently; and warm TCP connections are more efficient than cold ones.

HTTP/2 introduces an extra step: it divides HTTP/1.x messages into frames which are embedded in a stream. Data and header frames are separated, which allows header compression. Several streams can be combined together, a process called multiplexing, allowing more efficient use of underlying TCP connections.

HTTP Messages - HTTP | MDN (5)

HTTP frames are now transparent to Web developers. This is an additional step in HTTP/2, between HTTP/1.1 messages and the underlying transport protocol. No changes are needed in the APIs used by Web developers to utilize HTTP frames; when available in both the browser and the server, HTTP/2 is switched on and used.

Conclusion

HTTP messages are the key in using HTTP; their structure is simple, and they are highly extensible. The HTTP/2 framing mechanism adds a new intermediate layer between the HTTP/1.x syntax and the underlying transport protocol, without fundamentally modifying it: building upon proven mechanisms.

HTTP Messages - HTTP | MDN (2024)
Top Articles
Critical and rare: the minerals Australia can supply to the world
DC Federal Money Laundering Penalties | Sentencing Factors
Kostner Wingback Bed
Victor Spizzirri Linkedin
Uca Cheerleading Nationals 2023
123 Movies Black Adam
Noaa Charleston Wv
Insidious 5 Showtimes Near Cinemark Tinseltown 290 And Xd
My Boyfriend Has No Money And I Pay For Everything
Nc Maxpreps
Puretalkusa.com/Amac
Publix 147 Coral Way
Planets Visible Tonight Virginia
Sams Gas Price Fairview Heights Il
Cool Math Games Bucketball
Caresha Please Discount Code
Alejos Hut Henderson Tx
Skyward Login Jennings County
Iu Spring Break 2024
Farmer's Almanac 2 Month Free Forecast
Virginia New Year's Millionaire Raffle 2022
2020 Military Pay Charts – Officer & Enlisted Pay Scales (3.1% Raise)
Loves Employee Pay Stub
Gentle Dental Northpointe
Barber Gym Quantico Hours
Soulstone Survivors Igg
Craig Woolard Net Worth
Mineral Wells Skyward
UCLA Study Abroad | International Education Office
Copper Pint Chaska
Xpanas Indo
Buhl Park Summer Concert Series 2023 Schedule
*!Good Night (2024) 𝙵ull𝙼ovie Downl𝚘ad Fr𝚎e 1080𝚙, 720𝚙, 480𝚙 H𝙳 HI𝙽DI Dub𝚋ed Fil𝙼yz𝚒lla Isaidub
Missing 2023 Showtimes Near Grand Theatres - Bismarck
Khatrimmaza
6143 N Fresno St
Craigslist Org Sf
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
Agematch Com Member Login
Raising Canes Franchise Cost
7543460065
Koninklijk Theater Tuschinski
Fapello.clm
140000 Kilometers To Miles
Bunkr Public Albums
Pulitzer And Tony Winning Play About A Mathematical Genius Crossword
Tfn Powerschool
Garland County Mugshots Today
Catchvideo Chrome Extension
Gary Vandenheuvel Net Worth
Dyi Urban Dictionary
Lagrone Funeral Chapel & Crematory Obituaries
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6515

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.