1

I'm trying to use the built-in SimpleHTTPServer in Python to serve a static page locally. I start it with python -m SimpleHTTPServer.

At the moment, the HTML is just

<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        Hi
    </body>
</html>

The server returns the page with status 200 but the browser console says ERR_CONTENT_LENGTH_MISMATCH and won't render anything. If I change the content to single line of text it shows up fine. Adding another line breaks it again. Per the comments, it seems like the problem is with newlines. I'm writing this in Sublime Text (on Windows) and using Chrome to view, if that helps.

serverpunk
  • 10,665
  • 15
  • 61
  • 95
  • 1
    Please share the code of how you are reading the content. There could be issues due to things like newline,spaces etc. which your code might not be parsing correctly since I recall something similar – codegeek Mar 14 '14 at 17:21
  • works on mine, get a title of `Test` and text saying `Hi` – Noelkd Mar 14 '14 at 17:25
  • It definitely seems like a newline issue - I updated the question with some more info. Thanks guys. – serverpunk Mar 14 '14 at 17:26

1 Answers1

2

It turned out to be a Sublime Text issue. Just had to change the line endings in View > Line Endings to Unix.

Big ups to this post:

Fixing Sublime Text 2 line endings?

Community
  • 1
  • 1
serverpunk
  • 10,665
  • 15
  • 61
  • 95
  • Fix the code that sets `Content-Length`. It should be calculated correctly whether the newline is `\n` or `\r\n`. – jfs Mar 14 '14 at 20:31