title: Handling 100-continue when redirecting a POST request from a Web API controller
body: <p>I have an <code>ApiController</code> which responds to a POST request by redirecting it via HTTP's status code 307. It does so using only information from the header, so the body of the request is not needed by this action. This action is equivalent to:</p>
  
  <pre><code>public HttpResponseMessage Post() {
      var url;
      // Some logic to construct the URL
      var response = new HttpResponseMessage(HttpStatusCode.TemporaryRedirect);
      response.Headers.Location = new System.Uri(url);
      return response;
  }
  </code></pre>
  
  <p>This is straightforward enough, but there is one improvement I would like to make. The request body could potentially contain a large amount of data, so I would like to leverage the HTTP status code 100 to make this request more efficient. With the controller as it is now, a conversation might look like this:</p>
  
  <pre><code>&gt; POST /api/test HTTP/1.1
  &gt; Expect: 100-continue
  &gt; ...
  
  &lt; HTTP/1.1 100 Continue
  
  &gt; (request body is sent)
  
  &lt; HTTP/1.1 307 Temporary Redirect
  &lt; Location: (the URL)
  &lt; ...
  </code></pre>
  
  <p>Since the request body is not needed by the redirection action, I would like to be able to shorten the conversation to:</p>
  
  <pre><code>&gt; POST /api/controller HTTP/1.1
  &gt; Expect: 100-continue
  &gt; ...
  
  &lt; HTTP/1.1 307 Temporary Redirect
  &lt; Location: (the URL)
  &lt; ...
  </code></pre>
  
  <p>I have spent the better part of a day researching how to accomplish this, and I have not been able to come up with a solution. In my research, I have learned:</p>
  
  <ul>
  <li>When the <code>ApiController</code>'s action executes, the <code>100 Continue</code> has already been sent.</li>
  <li>When the <code>ApiController</code> is constructed, the <code>100 Continue</code> has already been sent.</li>
  <li>When the <code>HttpApplication</code>'s <code>PreRequestHandlerExecute</code> event is triggered, the <code>100 Continue</code> response has not been sent.</li>
  <li>When a <code>DelegatingHandler</code> executes, the <code>100 Continue</code> has already been sent.</li>
  </ul>
  
  <p>Based on this, the best solution I have come up with so far is to create an <code>HttpModule</code> which uses the <code>RouteData</code> on the <code>RequestContext</code> to override the response when the <code>ApiController</code> in question is the recipient of the request. This is far from an ideal solution, however, for several reasons (code separation, not taking advantage of Web API's parameter binding, and bypassing additional logic in an <code>AuthorizeAttribute</code> on the <code>ApiController</code>).</p>
  
  <p>It seems as if there must be a better solution to this, but I have found very little information on how to properly handle the <code>Expect: 100-continue</code> header in a Web API application. <strong>What would be the simplest way to implement this <code>ApiController</code> to properly handle the <code>Expect: 100-continue</code> header?</strong></p>