Content-Length Error when IIS returns response with STATUS 302 RRS feed

  • Question

  • User-556018956 posted

    I have small FastCGI application on Python+Flask. Server 2012 R2, IIS 8.5.

    When I return from handler redirect( url_for(...), 302)  in Python code, Flask returns response  with some html about "You will be redirected" and properly set Content-Length in response object.

    IIS see response status code 302 and add another html to response content before already added by Flask:

    <head><title>Document Moved</title></head>
    <body><h1>Object Moved</h1>This document may be found <a HREF="...">here</a></body>

    But IIS don't set right value of Content-Length after code insertion.

    As result my customers see in browser source code of page where redirection was targeted.

    What can I do to resolve this problem?

    Tuesday, June 27, 2017 7:03 AM

All replies

  • User-460007017 posted

    Hi s.jmacov,

    You could enable the failed request tracing to figure out what's going on with the response header:


    I notice the httpcompression will also effect the size of content size. So if you need to avoid the wrong value, try to disable the dynamic/static compression.

    Best Regards,

    Yuk Ding

    Tuesday, June 27, 2017 8:57 AM
  • User-556018956 posted

    Hi, Yuk!

    If You change content of string, You must change Content-Length value in another place too (or use some function like length(string) ). And You do so in fact, if You good programmer.

    IIS injects additional html code in my response, builded by Python-Flask, and MUST change Content-Length too!

    It is not compression issue, and I don't need to trace something - IIS thinks that request and response absolutely normal.

    The question is - how disable in IIS 8.5 adding additional html in response content for status code 302 or what else can I do for correct wrong IIS behavior?

    Thursday, June 29, 2017 7:06 AM
  • User-460007017 posted

    Hi s.jmacov,

    IIS shouldn't add any additional html to your page. IIS is only be able to rewrite the attribute in  img/a/script/... tag if you have set the outbound rule.  If you want to disable this for your 302 response, just add the condition pattern or precondition with  {RESPONSE_STATUS} does not match 302.  Please enable the failed request tracing to check what's going on with your application.

    Best Regards,

    YUk Ding

    Friday, June 30, 2017 8:18 AM