Wednesday, November 10, 2010

Use netcat as a fake server to debug http issues

I had a problem with my http server where my cookie didn't seem to be accepted by the browser and resent. To debug the issue I wanted to be able to edit the headers that were being sent back to the browser. Here is the technique I used to quickly find the issue.

# use curl to pull the raw response
# from the server and the headers that were sent back

curl -D headers2 --raw > raw2.txt

# concatenate the headers and response into one file

cat headers2 raw2.txt > both2.txt

# cause netcat to listen on a specified port
# and cat your mock response to it

cat both2.txt | nc -l 8099

# netcat will sit and wait for your request
# now aim your browser at localhost:8099

After that you go to your browser at localhost:8099 and you'll get the response you set up.

No comments: