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

1

14

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?

Immortalize answered 29/10, 2012 at 20:53 Comment(0)
R
11

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.

Ras answered 31/10, 2012 at 23:40 Comment(3)
great find. It was indeed cleverly hidden.Immortalize
would you agree that content-range is the appropriate header for sending chunks of a file during upload? I was doubting between this header and the range header.Immortalize
I have no experience with this, but from reading the spec--yes. Range is a Request Header--seems to be meant for requesting a range. Content-Range, being an Entity Header, has meaning on a PUT request (for the client to identify to the server a chunk being sent to replace a portion of an existing resource) and on a GET response (for the server to identify to the client which chunk is being returned).Ras

© 2022 - 2024 — McMap. All rights reserved.