To start a web server that starts on port 80
sudo python -m SimpleHTTPServer 80
If you write, it will start up in one shot and you will be able to access the files in that directory. However, with this, debugging is not possible when the header is entered, so I made it a simple WEB server that displays the header.
printHeadersHttpServer.py
import SimpleHTTPServer
import SocketServer
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
print(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
SocketServer.TCPServer(("", 80), Handler).serve_forever()
Run and access with curl.
sudo python printHeadersHttpServer.py
curl http:localhost/peki.txt
The header is also output to the console as shown below. Fucking useful for debugging.
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Host: localhost
Accept: */*
localhost.localdomain - - [07/Oct/2015 20:20:15] "GET /peki.txt HTTP/1.1" 200 -
Recommended Posts