GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — "Illegal Character in query" in HttpConversionUtil · Issue #14591 · netty/netty

"Illegal Character in query" in HttpConversionUtil #14591

New issue
Copy link
New issue
Copy link
Closed
#16810
Closed
"Illegal Character in query" in HttpConversionUtil#14591
#16810
Copy link
Milestone
4.2.15.Final

Description

@yyy
yyy
opened on Dec 16, 2024
Issue body actions

Netty should be able to handle any valid URI. But currently io.netty.handler.codec.http2.HttpConversionUtil is relying on java.net.URI class, which supports https://datatracker.ietf.org/doc/rfc2396/, but does not support https://datatracker.ietf.org/doc/rfc3986/ . So, some legal characters in the URI path, e.g. {, are breaking the conversion.

Expected behavior

Any HTTP header with rfc3986-compliant path (and probably non-compiant too) should be convertable to Http2Headers

Actual behavior

IllegalArgumentException is rethrown caused by an exception in java.net.URI:

java.lang.IllegalArgumentException: Illegal character in query at index 63: https://bh.contextweb.com/bh/rtset?pid=558355&ev=1&us_privacy=${us_privacy}

	at java.base/java.net.URI.create(URI.java:906)
	at io.netty.handler.codec.http2.HttpConversionUtil.toHttp2Headers(HttpConversionUtil.java:441)
...
Caused by: java.net.URISyntaxException: Illegal character in query at index 63: https://bh.contextweb.com/bh/rtset?pid=558355&ev=1&us_privacy=${us_privacy}
	at java.base/java.net.URI$Parser.fail(URI.java:2976)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3147)
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3235)
	at java.base/java.net.URI$Parser.parse(URI.java:3177)
	at java.base/java.net.URI.<init>(URI.java:623)
	at java.base/java.net.URI.create(URI.java:904)
	... 71 more

Steps to reproduce

Use any code flow that converts HttpMessage object to Http2Headers using HttpConversionUtil with a URL with characters not supported by rfc2396.

Minimal yet complete reproducer code (or URL to code)

public class HttpConversionUtilTest {

    @Test
    void testToHttp2HeadersFromHttpRequest() {
        HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "https://bh.contextweb.com/bh/rtset?pid=558355&ev=1&us_privacy=${us_privacy}");
        
        Http2Headers http2Headers = HttpConversionUtil.toHttp2Headers(httpRequest, true);

        assertEquals("/bh/rtset?pid=558355&ev=1&us_privacy=${us_privacy}", http2Headers.path().toString());
    }
}

Netty version

4.1.115

JVM version (e.g. java -version)

OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)

OS version (e.g. uname -a)

Darwin us-m-ccloud01 22.6.0 Darwin Kernel Version 22.6.0: Fri Nov 15 17:21:49 PST 2024; root:xnu-8796.141.3.709.7~2/RELEASE_X86_64 x86_64

Activity

  1. normanmaurer commented on Dec 31, 2024

    @normanmaurer
    normanmaurer
    on Dec 31, 2024
    Member
    More actions

    @yyy as far as I know this should be fixed in JDK21: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URI.html

  2. yyy commented on Jan 3, 2025

    @yyy
    yyy
    on Jan 3, 2025
    Author
    More actions

    @normanmaurer That's definitely good to know, thank you! Unfortunately, we're still on JDK17 for now.

    I suppose it would be better to have consistent behavior across different Java versions, especially since the minimum required Java version for Netty is 1.6+ per https://netty.io/downloads.html.

  3. yyy commented on May 2, 2025

    @yyy
    yyy
    on May 2, 2025
    Author
    More actions

    Can I suggest an improvement to fall back in case URI parsing fails?

    I'm not too familiar with the PR process, but I feel this is a pretty trivial change.

    Ideally, I hope it can go into 4.1.x and up.

    ===================================================================
    diff --git a/node-server/services/web-proxy/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java b/node-server/services/web-proxy/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java
    --- a/node-server/services/web-proxy/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java
    +++ b/node-server/services/web-proxy/src/main/java/io/netty/handler/codec/http2/HttpConversionUtil.java	(date 1746153163686)
    @@ -438,9 +438,18 @@
                     out.path(new AsciiString(request.uri()));
                     setHttp2Scheme(inHeaders, out);
                 } else {
    -                URI requestTargetUri = URI.create(request.uri());
    -                out.path(toHttp2Path(requestTargetUri));
    -                // Take from the request-line if HOST header was empty
    +                URI requestTargetUri;
    +                try {
    +                    requestTargetUri = URI.create(request.uri());
    +                    out.path(toHttp2Path(requestTargetUri));
    +                    // Take from the request-line if HOST header was empty
    +                } catch (IllegalArgumentException e) {
    +                    // Unable to create parse request.uri as URI object
    +                    // fall back to extracting the path manually
    +                    String[] splitUrl = splitPath(request.uri());
    +                    requestTargetUri = URI.create(splitUrl[0]);
    +                    out.path(new AsciiString(splitUrl[1]));
    +                }
                     host = isNullOrEmpty(host) ? requestTargetUri.getAuthority() : host;
                     setHttp2Scheme(inHeaders, requestTargetUri, out);
                 }
    @@ -456,6 +465,26 @@
             return out;
         }
     
    +    private static String[] splitPath(String url) {
    +        String baseURL;
    +        String pathWithQuery;
    +
    +        int schemeEnd = url.indexOf("://");
    +        int startIdx = (schemeEnd != -1) ? schemeEnd + 3 : 0;
    +
    +        int pathStart = url.indexOf('/', startIdx);
    +        if (pathStart != -1) {
    +            baseURL = url.substring(0, pathStart);
    +            pathWithQuery = url.substring(pathStart);
    +        } else {
    +            baseURL = url;
    +            pathWithQuery = "/";
    +        }
    +
    +        return new String[] { baseURL, pathWithQuery };
    +    }
    +
    +
         public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders) {
             if (inHeaders.isEmpty()) {
                 return EmptyHttp2Headers.INSTANCE;
    
    
  4. daguimu
    added a commit that references this issue on May 11, 2026

    Fall back to manual split when java.net.URI rejects HTTP/2 request URI

    This issue will close once commit c80f29c is merged into the '4.1' branch.
    c80f29c
  5. yawkat
    linked a pull request that will close this issueHTTP/2: Parse request-target path like Vert.x #16810on May 28, 2026
  6. yawkat
    closed this as completedon May 28, 2026
  7. normanmaurer
    added this to the 4.2.15.Final milestone on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.2.15.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.