Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Line Python Webserver

Tags:

python

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...

like image 691
RoadieRich Avatar asked Nov 09 '11 00:11

RoadieRich


People also ask

Can Python be used for web server?

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.

What does Python HTTP server do?

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.


2 Answers

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

like image 81
Håvard Avatar answered Oct 08 '22 19:10

Håvard


Was it perchance perl? favourite one liners

perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })' 
like image 35
Kinjal Dixit Avatar answered Oct 08 '22 18:10

Kinjal Dixit