Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 491
Toad Avatar asked Oct 29 '12 20:10

Toad


People also ask

What is content range header?

The Content-Range response HTTP header indicates where in a full body message a partial message belongs. Header type. Response header, Payload header. Forbidden header name.

What is Web API Accept header?

The Accept request HTTP header indicates which content types, expressed as MIME types, the client is able to understand. The server uses content negotiation to select one of the proposals and informs the client of the choice with the Content-Type response header.

When building an action for an ASP Net core Web API controller What should be returned in case the operation completed successfully?

Returns an HTTP 201 status code if successful.

Why is Web API required?

Web APIs allow businesses to access 3rd-party data and seamlessly integrate it anywhere and anytime it's required, offering unmatched data processing efficiencies and cost savings. APIs have transformed the way businesses interact with each other and the way they provide value to their customers.


1 Answers

It is not stripped off. Look for it in Request.Content.Headers. It looks like they 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 it 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):

  • HttpRequestHeaders: Represents the collection of Request Headers as defined in RFC 2616.
  • HttpResponseHeaders: Represents the collection of Response Headers as defined in RFC 2616.
  • HttpContentHeaders: Represents the collection of Content Headers as defined in RFC 2616. Content-Range is an Entity Header, so ContentRange is in HttpContentHeaders.

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

like image 177
Pete Klein Avatar answered Sep 19 '22 15:09

Pete Klein