Skip to content

Commit 65e68ac

Browse files
committed
Use first() instead of sole() on HTTP fields #39
Browsers generally ignore duplicate field values so we should do the same.
1 parent 0920cec commit 65e68ac

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/org/netpreserve/jwarc/HttpRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static HttpRequest parse(ReadableByteChannel channel, ByteBuffer buffer,
8484
copyTo.write(buffer.duplicate());
8585
}
8686
MessageHeaders headers = parser.headers();
87-
long contentLength = headers.sole("Content-Length").map(Long::parseLong).orElse(-1L);
87+
long contentLength = headers.first("Content-Length").map(Long::parseLong).orElse(-1L);
8888
LengthedBody body = LengthedBody.create(channel, buffer, contentLength);
8989
return new HttpRequest(parser.method(), parser.target(), parser.version(), headers, body);
9090
}

src/org/netpreserve/jwarc/HttpResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static HttpResponse parse(ReadableByteChannel channel, WritableByteChann
8686
SeekableByteChannel seekable = (SeekableByteChannel) channel;
8787
contentLength = seekable.size() - seekable.position() + buffer.remaining();
8888
} else {
89-
contentLength = headers.sole("Content-Length").map(Long::parseLong).orElse(0L);
89+
contentLength = headers.first("Content-Length").map(Long::parseLong).orElse(0L);
9090
}
9191
body = LengthedBody.create(channel, buffer, contentLength);
9292
}

src/org/netpreserve/jwarc/Message.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public MessageVersion version() {
5757
* Returns "application/octet-stream" if the Content-Type header is missing.
5858
*/
5959
public MediaType contentType() {
60-
return headers.sole("Content-Type").map(MediaType::parse).orElse(MediaType.OCTET_STREAM);
60+
return headers.first("Content-Type").map(MediaType::parse).orElse(MediaType.OCTET_STREAM);
6161
}
6262

6363
void serializeHeaderTo(Appendable output) throws IOException {

0 commit comments

Comments
 (0)