Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between the two Web API headers response.Content.Headers and response.Headers

I find WebAPI separate HTTP response headers into different places, one is in Response.Headers, the other in in Response.Content.Headers. For example, etag is in Response.Headers while lastModified is in the other. What is the reason behind that?

like image 868
Bargitta Avatar asked Apr 22 '14 01:04

Bargitta


People also ask

What is the difference between request headers and response headers?

Request headers contain more information about the resource to be fetched, or about the client requesting the resource. Response headers hold additional information about the response, like its location or about the server providing it.

What are response headers in API?

A response header is an HTTP header that can be used in an HTTP response and that doesn't relate to the content of the message. Response headers, like Age , Location or Server are used to give a more detailed context of the response.

What are HTTP headers?

When a HTTP request is made, and a HTTP response given by a web server, the request or response is usually accompanied by additional information, contained in a so-called "HTTP header." The additional information in the HTTP headers help to ensure that the data pulled from the web server can be properly displayed in the browser window.

What is the difference between accept and content-type HTTP headers?

Difference between the Accept and Content-Type HTTP headers. So the Accept header tells the server the MIME-type of the resource the browser is looking for. For example, the server can send plain text, HTML, JSON, etc.

What is the difference between content and headers attributes in Python?

content: This attribute returns the raw bytes of the response content text: The text attribute returns the content as a normal UTF-8 encoded Python string json (): You can use the json () method to get the response content in JSON format The headers attributes returns a Python dictionary with all of the response headers.

What are API headers and why are they important?

Their job is to represent the meta-data associated with an API request and response. If you ever encounter issues with an API, the first place you should look is the headers, since they can help you track down any potential issues. This makes them a very important part of each request.


1 Answers

There are a couple of answers to that question. One is because that's the way the HTTP spec defines the headers.

RFC 2616

  • Content header fields here https://www.rfc-editor.org/rfc/rfc2616#section-7.1
  • Request header fields here https://www.rfc-editor.org/rfc/rfc2616#section-5.3
  • Response header fields here https://www.rfc-editor.org/rfc/rfc2616#section-6.2

The other more practical reason for separating out the content headers is that it is easier write code that processes data into HTTP payloads and sets the related headers, independent of the request/response objects.

Unfortunately, the more recent HTTPbis specification did some reorganization of where they think headers should go and now LastModified and Allow are considered response fields, not content fields. This means that the headers as defined in System.Net.HttpHeaders will no longer match the spec, which really sucks. It also means that we are probably stuck with LastModified as a HttpContent header and Etag as a response header.

HTTPbis

  • Content related headers are defined here.
  • Request headers here.
  • Response headers here.
like image 158
Darrel Miller Avatar answered Oct 22 '22 03:10

Darrel Miller