Issue #083 [Fixed/closed] - Complete Content-Length HTTP header for responses

Posted by andreas.riegg

Testing WebIOPi with apigee console lead to errors that have to do with partly missing Content-Length header of HTTP responses.

This change fixes this.

http.py

def sendResponse(self, code, body=None, contentType="text/plain"):
    if code >= 400:
        if body != None:
            self.send\_error(code, body)
        else:
            self.send\_error(code)
    else:
        self.send\_response(code)
        self.send\_header("Cache-Control", "no-cache")
        if body != None:
            self.send\_header("Content-Type", contentType);
            encodedBody = body.encode();                           # Added Rgg
            self.send\_header("Content-Length", len(encodedBody));  # Added Rgg
            self.end\_headers();
            self.wfile.write(encodedBody)                          # Changed Rgg
    self.logRequest(code)

Maybe coap.py also needs this kind of change but I did not look at this one so far.

Andreas


Comment 1

Posted by trouch

This issue was closed by revision r1433.