Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am looking for a command line tool that listens on a given part, happily excepts every HTTP POST request and dumps it.

I want to use it for testing purposes, i.e. for testing clients that issue HTTP POST requests.

That means I am searching the counterpart to curl -F (which I can use to send test HTTP POSTs to a HTTP server).

Perhaps something like socat TCP4-LISTEN:80,fork,bind=127.0.0.1 ... - but socat is not enough because it does not talk HTTP.

share|improve this question
    
Maybe I don't understand the question correctly, but if all you need is to dump the POST request, you can use netcat (nc on some systems) with the -l (listen) and -p (port number) options. –  peterph Dec 8 '12 at 0:23
    
@peterph, you can use nc for partial testing - but I can see following disadvantages: 1) it does not send HTTP status code 2) I have to hit Ctrl+D after I see the request to close the connection 3) it does not know how to react upon then 'Expect: 100-continue' header 4) it does not know how to handle the 'Transfer-Encoding: chunked' header - it probably just displays the first (probably) empty chunk –  maxschlepzig Dec 8 '12 at 0:43

1 Answer 1

up vote 1 down vote accepted

Simple core command line tools like nc, socat seem not to be able to handle the specific HTTP stuff going on (chunks, transfer encodings, etc.). As a result this may produce unexpected behaviour compared to talking to a real web server. So, my first thought is to share the quickest way I know of setting up a tiny web server and making it just do what you want: dump all output.

The shortest I could come up with using Python Tornado:

#!/usr/bin/env python

import tornado.ioloop
import tornado.web
import pprint

class MyDumpHandler(tornado.web.RequestHandler):
    def post(self):
        pprint.pprint(self.request)

if __name__ == "__main__":
    tornado.web.Application([(r"/.*", MyDumpHandler),]).listen(8080)
    tornado.ioloop.IOLoop.instance().start()

Replace the pprint line to output only the specific fields you need, for example self.body or self.headers. In the example above it listens on port 8080, on all interfaces.

Alternatives to this are plenty. web.py, Bottle, etc.

(I'm quite Python oriented, sorry)


If you don't like its way of outputting, just run it anyway and try tcpdump like this:

tcpdump -i lo 'tcp[32:4] = 0x484f535420'

to see a real raw dump of all HTTP-POST requests. Alternatively, just run Wireshark.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.