Sunday, May 14, 2017

Announcing ssweb single shot webserver in Python

Announcing ssweb single shot webserver in Python


This blog post announces ssweb, a single-shot HTTP server library in Python 2.x. Single-shot means is that the webserver accepts only a single incoming HTTP connection, handles it, and then exits immediately.

Such a server can be used as a redirect target in the web-based OAuth authentication protocol, to receive the freshly generated OAuth token. In this case the program is a command-line tool running a HTTP server for a short amount of time, to make the passwordsless login more convenient for the user, without having to manually copy-paste token. If it doesnt sound useful, then its most probably not useful for you right now.

Example usage:

$ wget -O ssweb.py http://raw.githubusercontent.com/pts/ssweb/master/ssweb.py
$ python ssweb.py
URL: http://127.0.0.1:40464/foo
{res_body: Shot., req_head: GET /foo HTTP/1.0 Host: 127.0.0.1:40464 User-Agent: Python-urllib/1.17 , client_addr: (127.0.0.1, 40026), res_head: HTTP/1.0 200 OK Content-Type: text/plain Content-Length: 5 , req_body: }
Shot.
$ python ssweb.py x
Please visit URL: http://127.0.0.1:59872/foo
... (after visiting the URL in Firefox)
{res_body: Shot., req_head: GET /foo HTTP/1.1 Host: 127.0.0.1:59872 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive , client_addr: (127.0.0.1, 50702), res_head: HTTP/1.0 200 OK Content-Type: text/plain Content-Length: 5 , req_body: }
get
 

Copyright © Video game tester Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger