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


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 URL for this entry:

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