[#4244] Convert urlencoded uri to http2 path correctly

Motivation:

HttpConversionUtil.toHttp2Headers does not convert urlencoded uri to http2 path properly.

Modifications:

Use getRawPath(), getRawQuery(), getRawFragment() in java.net.URI when converts to http2 path

Result:

HttpConversionUtil.toHttp2Headers does not urldecode uri unproperly.
This commit is contained in:
fratboy 2015-09-22 01:08:03 +09:00 committed by Scott Mitchell
parent 94bf412edb
commit a10cd9315a
2 changed files with 25 additions and 8 deletions

View File

@ -353,18 +353,18 @@ public final class HttpConversionUtil {
* <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>.
*/
private static AsciiString toHttp2Path(URI uri) {
StringBuilder pathBuilder = new StringBuilder(length(uri.getPath()) +
length(uri.getQuery()) + length(uri.getFragment()) + 2);
if (!isNullOrEmpty(uri.getPath())) {
pathBuilder.append(uri.getPath());
StringBuilder pathBuilder = new StringBuilder(length(uri.getRawPath()) +
length(uri.getRawQuery()) + length(uri.getRawFragment()) + 2);
if (!isNullOrEmpty(uri.getRawPath())) {
pathBuilder.append(uri.getRawPath());
}
if (!isNullOrEmpty(uri.getQuery())) {
if (!isNullOrEmpty(uri.getRawQuery())) {
pathBuilder.append('?');
pathBuilder.append(uri.getQuery());
pathBuilder.append(uri.getRawQuery());
}
if (!isNullOrEmpty(uri.getFragment())) {
if (!isNullOrEmpty(uri.getRawFragment())) {
pathBuilder.append('#');
pathBuilder.append(uri.getFragment());
pathBuilder.append(uri.getRawFragment());
}
String path = pathBuilder.toString();
return path.isEmpty() ? EMPTY_REQUEST_PATH : new AsciiString(path);

View File

@ -157,6 +157,23 @@ public class HttpToHttp2ConnectionHandlerTest {
verifyHeadersOnly(http2Headers, writePromise, clientChannel.writeAndFlush(request, writePromise));
}
@Test
public void testOriginFormRequestTargetHandledFromUrlencodedUri() throws Exception {
bootstrapEnv(2, 1, 0);
final FullHttpRequest request = new DefaultFullHttpRequest(
HTTP_1_1, GET, "/where%2B0?q=now%2B0&f=then%2B0#section1%2B0");
final HttpHeaders httpHeaders = request.headers();
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "http");
final Http2Headers http2Headers =
new DefaultHttp2Headers().method(new AsciiString("GET"))
.path(new AsciiString("/where%2B0?q=now%2B0&f=then%2B0#section1%2B0"))
.scheme(new AsciiString("http"));
ChannelPromise writePromise = newPromise();
verifyHeadersOnly(http2Headers, writePromise, clientChannel.writeAndFlush(request, writePromise));
}
@Test
public void testAbsoluteFormRequestTargetHandledFromHeaders() throws Exception {
bootstrapEnv(2, 1, 0);