Skip to content

Commit c3d34c2

Browse files
author
Joshua
committed
Fixed the Header Implementation
Changed the Version
1 parent 7be07e9 commit c3d34c2

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can also download the newest version from the [releases](https://github.com/
1515
<dependency>
1616
<groupId>de.joshicodes</groupId>
1717
<artifactId>webapi</artifactId>
18-
<version>1.3.1</version>
18+
<version>1.3.1b</version>
1919
</dependency>
2020
```
2121

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>de.joshicodes</groupId>
88
<artifactId>webapi</artifactId>
9-
<version>1.3.1</version>
9+
<version>1.3.1b</version>
1010

1111
<build>
1212
<plugins>

src/main/java/de/joshicodes/webapi/Webserver.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,15 @@ private boolean serve(Route request, HttpExchange exchange) throws IOException {
240240
private void write(ResponseData response, HttpExchange exchange) throws IOException {
241241
String body = response.getBody();
242242
if(body != null) {
243-
exchange.sendResponseHeaders(response.getStatusCode(), body.length());
244243

245244
if(response.getHeaders() != null)
246-
response.getHeaders().forEach((key, value) -> exchange.getResponseHeaders().add(key, value));
245+
response.getHeaders().forEach((key, value) -> exchange.getResponseHeaders().put(key, Arrays.asList(value.split(","))));
247246

248-
if(response.getContentType() != null)
247+
if(response.getContentType() != null) {
249248
exchange.getResponseHeaders().add("Content-Type", response.getContentType());
249+
}
250+
251+
exchange.sendResponseHeaders(response.getStatusCode(), body.length());
250252

251253
exchange.getResponseBody().write(body.getBytes());
252254
exchange.getResponseBody().close();

src/main/java/de/joshicodes/webapi/request/ResponseData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public Builder setContentType(String contentType) {
115115

116116
/**
117117
* Sets a header of the response
118+
* To set multiple headers, split the key and value with a <code>,</code><br>
118119
* @param key The key of the header
119120
* @param value The value of the header
120121
* @return This builder object

0 commit comments

Comments
 (0)