Examining request headers with netcat
How to use Netcat to examine request headers from user agents or applications.
Outside in Request Headers ¶
If you are writing web applications in an increasingly distributed world the chances are you will be using other web services outside your application. Often these services expect headers to be set for things like User-Agent and Authorization. Most frameworks allow you to dump the headers for the request you are making but to be really sure of the headers you are sending you may want to examine them from the outside in.
You can do this with netcat. Netcat is touted as the TCP/IP Swiss Army knife and with Network Programming becoming more important is an excellent tool.
netcat -lp 10839
This instructs netcat to listen on port 10839. Now you can make a request to it and see what your application or user agent is sending.
Here’s an example with the w3m browser
The request headers are logged to the console.
GET / HTTP/1.0
Accept: text/html, text/*;q=0.5, image/*
Accept-Encoding: gzip, compress, bzip, bzip2, deflate
Here’s another example with the Chromium browser in incognito mode.
GET / HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
More likely you will want to direct a request from within your application to netcat to verify your headers. Netcat is a super simple way to quickly debug and examine headers from outside your application.
Can you help make this article better? You can edit it here and send me a pull request.
API design for an event-driven world
REST and HATEOAS are designed around request response cycles. New thinking is needed for bidirectional, event-driven, realtime APIs.
Being a Parent and Working in Technology
Being a parent brings challenges to working as an engineer in Technology. In my experience with good software practices it can work.
The commoditisation of hack days
Far from be a chance to play and experiment sponsored hack days heap pressure on creative developers willing to give their time for free.