Created
December 21, 2017 18:54
-
-
Save ItGumby/9a61dc493eb9ba2bd71f344e08ae3d36 to your computer and use it in GitHub Desktop.
WebServer.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env groovy | |
import com.sun.net.httpserver.HttpServer | |
/** | |
* http://localhost:8080/hello | |
*/ | |
HttpServer.create(new InetSocketAddress(8080), 0).with { | |
createContext("/hello") { http -> | |
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
from http://glaforge.appspot.com/article/the-jdk-built-in-web-server-with-apache-groovy