Toad
Toad

Reputation: 15935

Why is the content-range header stripped from requests in ASP.NET Web API?

I'm creating an API in which it is possible to upload a file in a chunked manner.

Going by this Stackoverflow question and answer, the content-range header seems most appropriate for this.

However, in the controller action the header has been stripped so I can't access it. When I use the 'range' header it is available in the request headers collection.

Anyone an idea why the Content-Range is stripped from Requests?

Upvotes: 14

Views: 3059

Answers (1)

Pete Klein
Pete Klein

Reputation: 700

It is not stripped off. Look for it in Request.Content.Headers. It looks like the ASP.NET team aligned the headers with the HTTP/1.1 specifications--moving Entity Headers to Request.Content.Headers.
I tried it in a sample request and found it there.

I found this change after reading the relevant sections of RFC 2616. I've been going over RFC 2616 lately because the chief author, Fielding, is also the inventor of the REST architectural style, and I am trying to follow that style using ASP.NET Web API.

I realized that there was a distinction between "request", "response", "general" (used on both request and response but not entity related) and "entity" headers.

Looks as if the ASP.NET team revised the class model to better mirror the RFC, creating three subclasses of HttpHeaders:

  • HttpRequestHeaders for "5.3 Request Header Fields" and "4.5 General Header Fields"
  • HttpResponsHeaders for "6.2 Response Header Fields" and "4.5 General Header Fields"
  • HttpContentHeaders for "7.1 Entity Header Fields"

These are the verbatim descriptions of the three classes in MSDN (the links are mine):

Note, though that the class description on MSDN is a bit mistaken - there is no Content Headers definition in the RFC, but it is clear they meant Entity Headers.

Upvotes: 11

Related Questions