Monday, 10 November 2008

Checking HTTP Headers

Disclaimer: This post has nothing to do with Grails, other than the application we're testing is a grails app!

We're starting to "productize" our application. One of the stories is to ensure all javascript, CSS and image files are served with an appropriate set of HTTP headers so they can be cached effectively. For this we're using good old HTTP unit (I'll post about that more when we're finished), but in the meantime I've found the 'tcpdump' command very useful.
sudo tcpdump -A -ilo0 -t -s 1500 port 8080

-A prints ASCII
-i specifies the interface (I'm testing locally so lo0 is the loopback interface)
-t supresses timestamps
-s How many bytes to print (I wanted to see the full packet so set it to 1500)
port 8080 Tells tcpmon to only show me stuff going to or coming from port 8080

This results in output like

...GET /script/N259177905/bundles/stuff.js HTTP/1.1
User-Agent: httpunit/1.5
Cookie: splash=false
Cache-Control: no-cache
Pragma: no-cache
Host: localhost:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive


IP localhost.http-alt > localhost.53121: . ack 1892 win 65535 >nop,nop,timestamp 219937537 219937537<
E..4.n@.@...............:.,A.........(.....
...
IP localhost.http-alt > localhost.53121: . 197931:214263(16332) ack 1892 win 65535 <nop,nop,timestamp 219937537 219937537>
E.@.q.@.@...............:.,A........=......
...HTTP/1.1 200 OK
Content-Type: text/javascript; charset=UTF-8
Expires: Sat, 10 Nov 2018 11:24:54 GMT
Cache-Control: public, max-age=315360000, post-check=315360000, pre-check=315360000
Last-Modified: Sun, 06 Nov 2005 12:00:00 GMT
ETag: 2740050219
Transfer-Encoding: chunked
Server: Jetty(6.1.4)

6000
;(function(){function r(val,args){for(var x=0;x<args.length;x++){val=val.replace('{'+x+'}',args[x]);}
return val;}
function p(){var val=arguments[0];var ret;if(val.indexOf('{0}')!=-1)
ret=function(){return r(val,arguments);}
else ret=function(){return val;}
...

I'm sure there's more I could do to fine tune the output, but it's a good starter for 10!

No comments: