Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between BaseHTTPServer and SimpleHTTPServer? When and where to use them?

What is the difference between BaseHTTPServer and SimpleHTTPServer? When and where should I use these?

like image 655
Sriram Avatar asked Nov 02 '09 08:11

Sriram


People also ask

How does Python HTTP server work?

HTTP Web Server is simply a process which runs on a machine and listens for incoming HTTP Requests by a specific IP and Port number, and then sends back a response for the request.

How do I close an HTTP server in Python?

CTRL+C is pressed to stop the server.


1 Answers

BaseHTTPServer is a HTTP server library. It understands the HTTP protocol and let your code handle requests. It doesn't have any "logic" on it's own. SimpleHTTPServer is built on top of BaseHTTPServer and handles requests in a similar way normal HTTP servers do, i.e. serve files from the file-system. In most cases you will want only BaseHTTPServer, as a base for implementing some development server for a web application.

If you are interested in working on a web application, not writing a HTTP server, you are probably looking for the WSGI interface. It allows you to write web aplications without depending on a specific server. There are also multiple frameworks that simplify the process.

like image 141
Lukáš Lalinský Avatar answered Sep 17 '22 13:09

Lukáš Lalinský