« Groovy XMLRPC: Practice Scripts | Main | Groovy 1.6.2 Released »

04/23/2009

Groovy Script: Use HTTP Builder to Check Web Server Type

With the help of some folks on the groovy-user mailing list, I wrote the following script to pull the server name header from an HTTP HEAD request. Mostly, I use this for verification purposes when setting ServerTokens to Prod on an apache server or when suppressing the tomcat server identity. The script uses Tom Nichols' HTTP Builder module for groovy. Running it is pretty straightforward as the script only takes one argument; enter the URL of the site you want to test. For example:

./checkServerType.groovy http://blogs.techstacks.com/

#!/usr/bin/env groovy

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.HEAD
import static groovyx.net.http.ContentType.TEXT

// create a new builder
def http = new HTTPBuilder( args[0] )

http.request( HEAD, TEXT ) {req ->
response.success = { resp ->
println " ${resp.getFirstHeader('Server')} "
}
response.failure = { resp ->
println "Server Response: ${resp.statusLine}"
}
}

TrackBack

TrackBack URL for this entry:
https://www.typepad.com/services/trackback/6a01156fbc6fe6970c0115722883b3970b

Listed below are links to weblogs that reference Groovy Script: Use HTTP Builder to Check Web Server Type:

Comments