Skip to content

Commit 684a331

Browse files
committed
Fixed TestHTTPSocket headers and incremented dependency versions
1 parent 2de4a7c commit 684a331

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

pom.xml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,17 @@
6060
<dependency>
6161
<groupId>org.junit.jupiter</groupId>
6262
<artifactId>junit-jupiter-api</artifactId>
63-
<version>5.9.0</version>
63+
<version>5.10.0</version>
6464
</dependency>
6565
<dependency>
6666
<groupId>io.undertow</groupId>
6767
<artifactId>undertow-core</artifactId>
68-
<version>2.2.19.Final</version>
68+
<version>2.3.8.Final</version>
6969
</dependency>
70-
<!--- Temporary fix for transitive vulnerabilities -->
71-
<dependency>
72-
<groupId>org.jboss.xnio</groupId>
73-
<artifactId>xnio-api</artifactId>
74-
<version>3.8.8.Final</version>
75-
</dependency>
76-
<!--- ============================================ -->
7770
<dependency>
7871
<groupId>org.junit.jupiter</groupId>
7972
<artifactId>junit-jupiter-engine</artifactId>
80-
<version>5.9.0</version>
73+
<version>5.10.0</version>
8174
<scope>test</scope>
8275
</dependency>
8376
</dependencies>

src/main/java/org/javawebstack/httpserver/adapter/IHTTPSocket.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ default IHTTPSocket setResponseStatus(int status) {
4343

4444
Set<String> getRequestHeaderNames();
4545

46-
String getRequestHeader(String name);
46+
default String getRequestHeader(String name) {
47+
List<String> headers = getRequestHeaders(name);
48+
if(headers == null || headers.size() == 0)
49+
return null;
50+
return headers.get(0);
51+
}
4752

4853
List<String> getRequestHeaders(String name);
4954

src/main/java/org/javawebstack/httpserver/test/TestHTTPSocket.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,33 @@ public class TestHTTPSocket implements IHTTPSocket {
1919
private final Map<String, List<String>> requestHeaders = new HashMap<>();
2020
private final Map<String, List<String>> responseHeaders = new HashMap<>();
2121

22-
public Map<String, List<String>> getRequestHeaders() {
23-
return requestHeaders;
24-
}
25-
26-
public Map<String, List<String>> getResponseHeaders() {
27-
return responseHeaders;
22+
public TestHTTPSocket(HTTPMethod method, String url) {
23+
this(method, url, null);
2824
}
2925

30-
public TestHTTPSocket(HTTPMethod method, String url) {
26+
public TestHTTPSocket(HTTPMethod method, String url, Map<String, String> headers) {
3127
this.requestMethod = method;
3228
String[] pathSplit = url.split("\\?", 2);
3329
requestPath = pathSplit[0];
3430
if(pathSplit.length == 2)
3531
requestQuery = pathSplit[1];
3632
else
3733
requestQuery = null;
34+
if(headers != null) {
35+
headers.entrySet().forEach(e -> {
36+
List<String> list = new ArrayList<>();
37+
list.add(e.getValue());
38+
this.requestHeaders.put(e.getKey(), list);
39+
});
40+
}
41+
}
42+
43+
public Map<String, List<String>> getRequestHeaders() {
44+
return requestHeaders;
45+
}
46+
47+
public Map<String, List<String>> getResponseHeaders() {
48+
return responseHeaders;
3849
}
3950

4051
public TestHTTPSocket setInputStream(InputStream inputStream) {
@@ -91,15 +102,11 @@ public String getRequestVersion() {
91102
}
92103

93104
public Set<String> getRequestHeaderNames() {
94-
return Collections.emptySet();
95-
}
96-
97-
public String getRequestHeader(String name) {
98-
return null;
105+
return requestHeaders.keySet();
99106
}
100107

101108
public List<String> getRequestHeaders(String name) {
102-
return null;
109+
return requestHeaders.get(name);
103110
}
104111

105112
public int getResponseStatus() {
@@ -115,7 +122,7 @@ public void writeHeaders() throws IOException {
115122
}
116123

117124
public String getRemoteAddress() {
118-
return null;
125+
return "127.0.0.1";
119126
}
120127

121128
}

0 commit comments

Comments
 (0)