Commit 22efcfd0 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

[WebView] Fix request body handling in WebServer for testing

This is a preliminary change for https://crrev.com/c/1928100.

Do not try to read request's payload body if
 - There is no Content-Length header, and
 - Transfer-Encoding: chunked is not found.

Bug: 1027011
Change-Id: I20de558733ba215419575d8fe87d624cef126f7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1936438Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721364}
parent 91b3a3fa
......@@ -181,8 +181,18 @@ public class WebServer {
return matchingHeaders;
}
private static boolean hasChunkedTransferEncoding(HTTPRequest req) {
List<String> transferEncodings = req.headerValues("Transfer-Encoding");
for (String encoding : transferEncodings) {
if (encoding.equals("chunked")) {
return true;
}
}
return false;
}
/** Parses an HTTP request from an input stream. */
static public HTTPRequest parse(InputStream stream) throws InvalidRequest, IOException {
public static HTTPRequest parse(InputStream stream) throws InvalidRequest, IOException {
boolean firstLine = true;
HTTPRequest req = new HTTPRequest();
ArrayList<HTTPHeader> mHeaders = new ArrayList<HTTPHeader>();
......@@ -250,7 +260,7 @@ public class WebServer {
offset += bytesRead;
}
req.mBody = content;
} else {
} else if (hasChunkedTransferEncoding(req)) {
ByteArrayOutputStream mBody = new ByteArrayOutputStream();
byte[] buffer = new byte[1000];
int bytesRead;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment