0

So, I made a simple socket server using python. And now I'm trying to structure a proper http response. However, I can't seem to find any sort of tutorial or spec that discusses how to format http responses.

Could someone point me to the right place?

3 Answers 3

3

RFC 2616.

Sign up to request clarification or add additional context in comments.

1 Comment

this RFC is the one and only true standard defining the HTTP protocol. if you are not used to RFCs, know that most standard protocols used on the internet are defined in an RFC. those documents are written in a clear and concise style and are updated (quite) regularly. there are some websites whose job is to list and collect those RFCs, along with their status/updates: you may try rfc-editor.org for example.
2

You may want to check out the following article:

The section Sample HTTP Exchange could help you getting started. Quoting:

The server should respond with something like the following, sent back through the same socket:

HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html
Content-Length: 1354

<html>
<body>
<h1>Happy New Millennium!</h1>
(more file contents)
  .
  .
  .
</body>
</html>

After sending the response, the server closes the socket.

The full protocol is defined in RFC 2616 if you want to get serious about this.

Comments

2

The urllib2 python standard library module helps you add http headers to your request.

Look in here for an example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.