CHAPTER 10

image

HTTP Servers

How can a Python program run as a server responding to HTTP requests? In Chapter 7, you learned several basic socket and concurrency patterns for writing a TCP-based network server. With HTTP, it is unlikely that you will ever need to write anything that low-level because the protocol’s popularity has resulted in off-the-shelf solutions for all of the major server patterns that you might need.

While this chapter will focus on third-party tools, the Standard Library does have an HTTP server implementation built in. It can even be invoked from the command line.

$ python3 -m http.serverServing HTTP on 0.0.0.0 port 8000 ... ...

Get Foundations of Python Network Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.