I have an ApiController that responds to a POST request by redirecting it through an HTTP status code of 307. It does this using only the information from the header, so the request body is not required by this action. This action is equivalent to:
public HttpResponseMessage Post() { var url;
It's simple enough, but there is one improvement I would like to make. The request body can potentially contain a large amount of data, so I would like to use the HTTP status code 100 to make this request more efficient. With the controller, as now, the conversation may look like this:
> POST /api/test HTTP/1.1 > Expect: 100-continue > ... < HTTP/1.1 100 Continue > (request body is sent) < HTTP/1.1 307 Temporary Redirect < Location: (the URL) < ...
Since the request body is not required by the redirect action, I would like to shorten the conversation to:
> POST /api/controller HTTP/1.1 > Expect: 100-continue > ... < HTTP/1.1 307 Temporary Redirect < Location: (the URL) < ...
I spent most of the day learning how to do this, and I could not find a solution. In my research, I found out:
- When the
ApiController action is ApiController , 100 Continue already dispatched. - When
ApiController built, 100 Continue already shipped. - When the
HttpApplication PreRequestHandlerExecute event HttpApplication , 100 Continue response is not sent. - When the
DelegatingHandler is executed, a 100 Continue has already been sent.
Based on this, the best solution I've come up with so far is to create an HttpModule that uses the RouteData on the RequestContext to override the response when the ApiController is the receiver of the request. However, this is far from an ideal solution for several reasons (code separation that does not use web API parameter binding and bypassing additional logic in AuthorizeAttribute on ApiController ).
There seems to be a better solution for this, but I have found very little information on how to properly handle the Expect: 100-continue header in a web API application. What would be the easiest way to implement this ApiController to properly handle the Expect: 100-continue header?
source share