Skip to content

Commit

Permalink
Added headers parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Dec 22, 2024
1 parent fcf3f2a commit b49c959
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/groovy/it/fulminazzo/railway/ContentHandler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class ContentHandler implements HttpHandler {
*/
static class HTTPResponse {
final int responseCode
final Map<String, List<String>> headers
final String message
final InputStream body

Expand All @@ -132,11 +133,39 @@ class ContentHandler implements HttpHandler {
* @param responseCode the code
* @param message the message displayed by the logger
* @param body the body itself
* @param headers the headers for the response
*/
HTTPResponse(@NotNull HTTPCode responseCode, @NotNull String message, @NotNull InputStream body) {
HTTPResponse(@NotNull HTTPCode responseCode, @NotNull String message, @NotNull InputStream body,
@Nullable Map<String, List<String>> headers) {
this.responseCode = responseCode.code
this.message = Objects.requireNonNull(message, 'Expected message to not be null')
this.body = Objects.requireNonNull(body, 'Expected body to not be null')
this.headers = new LinkedHashMap<>()
if (headers != null) this.headers.putAll(headers)
}

/**
* Instantiates a new HTTP response
*
* @param responseCode the code
* @param message the message displayed by the logger
* @param body the body itself
*/
HTTPResponse(@NotNull HTTPCode responseCode, @NotNull String message, @NotNull InputStream body) {
this(responseCode, message, body, null)
}

/**
* Instantiates a new HTTP response
*
* @param responseCode the code
* @param message the message displayed by the logger
* @param body the body itself
* @param headers the headers for the response
*/
HTTPResponse(@NotNull HTTPCode responseCode, @NotNull String message, @NotNull String body,
@Nullable Map<String, List<String>> headers) {
this(responseCode, message, new ByteArrayInputStream(body.bytes), headers)
}

/**
Expand Down

0 comments on commit b49c959

Please sign in to comment.