title: IIS7 refuses chunked-encoded file upload
body: <p>I have a Windows/Apache2/PHP app that receives file using chunked encoding. The reason is that the <em>file</em> uploaded is dynamic and its length is not known before transfer. This has always worked fine out of the box.</p>
  
  <p>Now I need to port the app to IIS7/PHP. 
  The problem is that IIS fails to receive the chunked file: When file is uploaded, the server just does not respond at all. How do I solve this?</p>
  
  <p>Note that in my test, I don't even use PHP. I simply have a .php extension because IIS refuses a POST on .htm file (which makes sense).</p>
  
  <p><a href="https://stackoverflow.com/questions/338624/why-does-iis-not-support-chunked-transfer-encoding/1208775#1208775">As suggested by rupello in this answer</a>, I made the test with cURL to make sure my client is not broken. cURL fails to get an answer as well, although it all works fine if transfer is not chunked.</p>
  
  <p>I made the following tests:</p>
  
  <p>test.php:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf8" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form method="post" enctype="multipart/form-data"&gt;
        File: &lt;input type="file" name="upfile" /&gt;
        &lt;input type="submit" value="go"/&gt;
    &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This command does not return (stuck waiting for an answer)</p>
  
  <pre><code>curl.exe http://serveur/test.php --form "upfile=@text.txt" 
     -H "Transfer-Encoding: chunked" -H "Expect:"
  </code></pre>
  
  <p>Note: <code>-H "Expect:"</code> is to suppress the <code>Expect 100-Continue</code> issued by curl. The result is the same without this header, execpt of course an additional roundtrip.
  Sent:</p>
  
  <pre><code>POST http://serveur/test.php HTTP/1.1
  User-Agent: curl/7.15.3 (i586-pc-mingw32msvc) libcurl/7.15.3 zlib/1.2.2
  Host: serveur
  Pragma: no-cache
  Accept: */*
  Connection: Keep-Alive
  Transfer-Encoding: chunked
  Content-Type: multipart/form-data; boundary=----------------------------310dbcc6761b
  
  8c
  ------------------------------310dbcc6761b
  Content-Disposition: form-data; name="upfile"; filename="text.txt"
  Content-Type: text/plain
  
  
  5
  hello
  30
  
  ------------------------------310dbcc6761b--
  
  0
  </code></pre>
  
  <p>Problem: Nothing returned by server. Server looks like it keeps waiting. curl does not return.</p>
  
  <p>The same command without the chunk encoding works as expected:</p>
  
  <p>Sent:</p>
  
  <pre><code>POST http://serveur/test.php HTTP/1.1
  User-Agent: curl/7.15.3 (i586-pc-mingw32msvc) libcurl/7.15.3 zlib/1.2.2
  Host: serveur
  Pragma: no-cache
  Accept: */*
  Connection: Keep-Alive
  Content-Length: 193
  Content-Type: multipart/form-data; boundary=----------------------------e2d761bc173a
  
  ------------------------------e2d761bc173a
  Content-Disposition: form-data; name="upfile"; filename="text.txt"
  Content-Type: text/plain
  
  hello
  ------------------------------e2d761bc173a--
  </code></pre>
  
  <p>Server now replies correctly:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Content-Type: text/html
  Server: Microsoft-IIS/7.5
  X-Powered-By: PHP/5.3.8
  X-Powered-By: ASP.NET
  Date: Mon, 21 Nov 2011 10:47:57 GMT
  Content-Length: 272
  
  &lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form method="post" enctype="multipart/form-data"&gt;
      File: &lt;input type="file" name="upfile" /&gt;
      &lt;input type="submit" value="go"/&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The test on plain-vanilla LAMP server with the same files and requests work fine.</p>
  
  <p>So how do I enable request chunk-encoding on IIS?</p>
  
  <p>Note: I did try the related ASP parameter, to no avail:</p>
  
  <pre><code>C:\...\inetsrv&gt;appcmd.exe set config /section:asp /enableChunkedEncoding:True
  Applied configuration changes to section "system.webServer/asp" for "MACHINE/
  WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"
  </code></pre>