Skip to content

Commit 545d462

Browse files
committed
Add some response features
1 parent f126f15 commit 545d462

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/express/http/response/Response.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.IOException;
1313
import java.io.OutputStream;
1414
import java.nio.file.Files;
15+
import java.util.List;
1516

1617
/**
1718
* @author Simon Reinisch
@@ -34,6 +35,37 @@ public Response(HttpExchange exchange) {
3435
this.BODY = exchange.getResponseBody();
3536
}
3637

38+
/**
39+
* Add an specific value to the reponse header.
40+
*
41+
* @param key The header name.
42+
* @param value The header value.
43+
* @return This Response instance.
44+
*/
45+
public Response setHeader(String key, String value) {
46+
HEADER.add(key, value);
47+
return this;
48+
}
49+
50+
/**
51+
* @param key The header key.
52+
* @return The values which are associated with this key.
53+
*/
54+
public List<String> getHeader(String key) {
55+
return HEADER.get(key);
56+
}
57+
58+
/**
59+
* Sets the response Location HTTP header to the specified path parameter.
60+
*
61+
* @param location The location.
62+
*/
63+
public void setLocation(String location) {
64+
HEADER.add("Location", location);
65+
setStatus(Status._302);
66+
send();
67+
}
68+
3769
/**
3870
* Set an cookie.
3971
*

0 commit comments

Comments
 (0)