I seem to remember seeing a single line implementation of a webserver a couple of years ago. I'm aware of SimpleHTTPServer and it's like, and that's not it - I think this was using Socket and select().
I thought it was on the Python Tutor mailing list, but an archive search hasn't revealed anything, nor has a google search. I was wondering if anyone here might have further leads I could look up - or ideally a link to the original.
Although I guess it's entirely possible that the original author has taken it down out of shame...
A webserver in Python can be setup in two ways. Python supports a webserver out of the box. You can start a web server with a one liner. But you can also create a custom web server which has unique functionality.
Python HTTP server is a kind of web server that is used to access the files over the request. Users can request any data or file over the webserver using request, and the server returns the data or file in the form of a response.
I'm pretty sure you can't have a webserver using sockets and select() on one line of code. Not even using semicolons, you'd have to have some loops and control structures.
Are you sure this isn't what you are looking for?
Python 3 version:
$ python -m http.server 8000 Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Python 2 version: python -m SimpleHTTPServer 8000
Was it perchance perl
? favourite one liners
perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With