6.1 Types of headings

The http request headers are actually service information for the http client and http server. But it is very important, and if you do not understand them at all, it will often go sideways to you. So at least read about them.

All http headers can be divided into 4 main groups:

# Header type Description Note
1 General Headers General headings Used in requests and responses
2 Request headers Request headers Used only in requests
3 response headers Response headers Only used in responses
4 Entity Headers Entity headers Accompany each message entity

6.2 User agent

The most important and popular header is User-Agent . This is a special string that describes which client is making the request to the server. This is the customer's name.

Often the server will tailor its response slightly to the requester. For example, if it is clear from the request that the request came from a mobile phone browser, then it can be given a mobile version of the HTML page.

It is not uncommon for spambots, download managers, and some browsers to send fake User-Agent strings to pretend to be legitimate customers. This situation is known as user agent spoofing or user agent spoofing.

For example, my User-Agent looks like this now:

Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0

It contains information about the browser, operating system, and web engine of the browser.

6.3 Content Type

The second most popular header is Content-Type . It is used to determine the MIME type of the resource that the server is serving.

Even at the dawn of the Internet, the types of media content transmitted were standardized for convenience. They are called Internet Media Types or MimeTypes for short . They fall into 9 categories:

  • application
  • audio
  • example
  • image
  • message
  • model
  • multipart
  • text
  • video

Examples:

Category Type Description
audio audio/mp4 Audio file in mp4 format
audio/aac AAC audio file
image image/gif gif picture
image/jpeg jpeg picture
image/png picture png
text text/css CSS file
text/html HTML file
video video/mpeg Video file in mpeg format
video/webm Video file in webm format
video/3gpp Video file in 3gpp format
application application/x-www-form-urlencoded Encoded data
application/zip Zip archive
application/javascript JavaScript
application/xml XML

Usually the server knows what data it gives. But if you are generating a server response with your own code, then you need to specify the response type (Content-Type) of your server.

6.4 Content Length

This header specifies the length of the server 's response . If in a simple way, then the size of the given file. You do not need to manually set this option. Although it can be useful to look at what the server gave, if for some reason the answer did not come all.

6.5 Accept Encoding

With this header, the client can indicate to the server that it supports various content compression algorithms . Thus, the server can first archive the content, for example, with a zip archive, then send it to the client, and the client can correctly restore the original content.

The advantage of archiving is that the smaller the file, the faster the transfer. Cons of archiving - additional load on the client and on the server. Archiving makes sense when transferring large files and often doesn't make sense when transferring small ones.

An example of such a header:

Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5

Where deflateand gzipare the supported data compression algorithms, and qdenotes the degree of compression.