Skip to content

Instantly share code, notes, and snippets.

@snydergd
Created June 11, 2019 01:46
Show Gist options
  • Save snydergd/49dbf63d3614e7ad242a324014ca98d0 to your computer and use it in GitHub Desktop.
Save snydergd/49dbf63d3614e7ad242a324014ca98d0 to your computer and use it in GitHub Desktop.
HTTP Dumper
import com.sun.net.httpserver.HttpServer
HttpServer.create(new InetSocketAddress(8899), 0).with {
createContext("/") { http ->
http.with {
println (requestMethod + " " + requestURI + " HTTP/1.1")
requestHeaders.each{
a,b -> b.each{
y -> println a + ": " + y
}
}
println ""
System.out << requestBody
requestBody.close()
println ""
}
http.responseHeaders.add("Content-type", "text/plain")
http.sendResponseHeaders(200, 0)
http.responseBody.withWriter { out ->
out << "Hello ${http.remoteAddress.hostName}!"
}
}
start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment