HTTP Messages, Status and Headers Notes - Hsanokklis/2023-2024-Tech-journal GitHub Wiki

HTTP Messages

  • Three body pats of the HTTP messages
    • start line
    • headers
    • entity body

Parts of a HTTP Message

  • The start line and headers are just ASCII text, broken up by lines
  • Each line ends with a two-character end-of-line sequence, consisting of a carriage return (ASCII 13) and a line-feed character(ASCII 10)
    • This end of line-sequence us written CRLF

image

  • The entity body or message body (or just plain body), is simply an option chuck of data.
    • Unlike the start line and headers, the body can contain text or binary or can be empty.

HTTP message Syntax

  • HTTP messages fall into two --->
    • Request messages
    • Response messages

Request messages

  • request a action from a web server

Response messages

  • Carry results of a request back to a client

image

Start Lines: Methods

image

  • The method begins the start line of requests i.e tells the server what to do.

image

Response Start Lines: Status Codes

  • Response status codes tells the client what happens

image

HTTP Request Header

image

Everything after the GET method is a header

HTTP Response Header

image

Everything after the 200 OK status is a header. DOCTYPE starts the content

HEAD Method

  • HEAD is identical to GET, except the server does not return the content in the HTTP response.
  • When you send a HEAD request, it means that you are only interested in the response code and the HTTP headers, not the document itself.
  • with this method the browser can:
    • check is a document has been modified, for caching purposes
    • Can check if the document exists at all
  • Usage:
    • If you have a lot of links on your website, you can periodically send HEAD requests to all of them to check for broken links
    • This works much faster than using GET

Response Headers Host

  • HTTP Request is sent to a specific IP address, but since most servers are capable of hosting multiple websites under the same IP, they must know which domain name the browser is looking for.

Response Headers User Agent

  • This header can carry several pieces of information such as
    • browser name and version
    • operating system name and version
    • default language
  • This is how websites can collect certain general information about their surfers systems
  • EX- can detect if the surfer is using a cell phone browser and redirect them to a mobile version of their website

Request Header Accept-Language

  • What language the client requests

Request Header Accept-Encoding

  • Whether the client support g-zip compression of HTML

Request Header IF-Modified-Since

  • If a page is cached on client, it will ask server if it has been modified since date
  • If not changed, server sends a 304 Not-Modified instead of page

Request Header Referrer

  • Tells server what page you are coming from