Content-Length Error when IIS returns response with STATUS 302RSS

3 replies

Last post Jun 30, 2017 08:18 AM by Yuk Ding

  • Content-Length Error when IIS returns response with STATUS 302

    Jun 27, 2017 07:03 AM|s.jmacov|LINK

    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?

  • Re: Content-Length Error when IIS returns response with STATUS 302

    Jun 27, 2017 08:57 AM|Yuk Ding|LINK

    Hi s.jmacov,

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

    https://docs.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis

    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

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Content-Length Error when IIS returns response with STATUS 302

    Jun 29, 2017 07:06 AM|s.jmacov|LINK

    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?

  • Re: Content-Length Error when IIS returns response with STATUS 302

    Jun 30, 2017 08:18 AM|Yuk Ding|LINK

    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

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.