Skip to content

Commit

Permalink
Added support for headers in handle method
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Dec 22, 2024
1 parent b49c959 commit 2924ff2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/groovy/it/fulminazzo/railway/ContentHandler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.slf4j.Logger
*/
class ContentHandler implements HttpHandler {
static final INDEX_NAME = 'index.html'
static final SERVER_NAME_VERSION = 'Railway/1.0'

final @NotNull File root
final @Nullable File notFoundPage
Expand Down Expand Up @@ -91,6 +92,8 @@ class ContentHandler implements HttpHandler {

this.logger.info("${requesterIp} <- ${responseCode} ${response.message}")

response.headers.forEach { k, v -> httpExchange.responseHeaders.put(k, v) }
httpExchange.responseHeaders.put('Server', SERVER_NAME_VERSION)
httpExchange.sendResponseHeaders(responseCode, responseBody.available())
output << responseBody
output.close()
Expand Down

0 comments on commit 2924ff2

Please sign in to comment.