Simple HTTP server for logging requests only [closed]
Asked Answered
P

2

38

I need to run a simple HTTP server that will only log incoming requests and nothing.

It should log whole requests' content. Like headers, cookies, body....

I need just simple solution that I can run in a few minutes and will work.

Implementation language is not important.

Something like Charles but HTTP server instead of proxy

Pungent answered 16/5, 2017 at 16:15 Comment(1)
try this webhook.siteColossal
B
56

For some super simple alternatives, there's netcat:

$ nc -l -p 8080

And python's inbuilt:

$ python -m SimpleHTTPServer 8080

(In recent versions of python, 3?) this is now:

$ python -m http.server 8080

Netcat won't serve responses so you may not get too far, SimpleHTTPServer won't show POST requests (at least). But occasionally I find both useful.

Bahner answered 9/8, 2017 at 8:5 Comment(5)
There are multiple versions of netcat out there with different behaviour, irritatingly. The -p flag tends to work even where it's optional.Bahner
For me on Mac OS X, nc -l -p <port> gave an error, while nc -l <port> worked but only kept nc listening for a single request. nc -k -l <port> keeps it going past the first request.Muslim
Be careful with the python http.server command, it will list your directory's files if you request '/' and allow you to download files.Incurvate
python -m http.server 8080 this one is interesting; But, can I make it to return 200 OK, instead of 404 Not Found?Slattern
It serves files from the directory you run it in, so if there's an index.html it'll serve that with a 200. If there's nothing in the directory you'll get 404s.Bahner
G
29

If you are looking for online HTTP server which will record all requests' information, you can use RequestBin. (Update in 2020: Unfortunately, RequestBin was offline now.)

If you need to make your own HTTP logging server, Node.js + Express is a good candidate. It's very easy and quickly to make:

  1. Install Node.js
  2. Install Express generator so that web application can be generated in seconds: npm install express-generator -g
  3. Generate a web application and install all dependencies:
    express myapp
    cd myapp
    npm install
  1. Edit myapp/app.js and insert following code block before the line app.use('/', index);:
    app.use(function(req, res) {
      console.log(req.headers);
      console.log(req.cookies);
      console.log(req.body);
      res.send('OK');
    });
  1. That's it. Now run DEBUG=myapp:* npm start in console and start the web applicaiton. All HTTP requests sent to host localhost:3000 will be recorded with their headers, cookies and body.
  2. If you need to write these logs into a file, a logger module can be used, such as log.
Goosestep answered 16/5, 2017 at 23:58 Comment(5)
I have implemented the proposed nodejs solution here : github.com/humblewolf/loghtZwolle
It seems the "RequestBin" website has been taken offline.Museum
@Zwolle Why using docker for something as simple as that?Roshelle
@Museum So sad that RequestBin has been offline :(Goosestep
@JeanPaul docker is even simpler :)Zwolle

© 2022 - 2024 — McMap. All rights reserved.