Repository navigation
Conversation
| override def parse(name: String, value: String, parserSettings: ParserSettings): (Uri.Path, Option[String]) = | ||
| try { | ||
| if (value.isEmpty) { | ||
| protocolError("Pseudo-header ':path' must not be empty") |
There was a problem hiding this comment.
There was a problem hiding this comment.
The ":path" pseudo-header field includes the path and query parts
of the target URI (the "path-absolute" production and optionally a
'?' character followed by the "query" production (see Sections 3.3
and 3.4 of [RFC3986]). A request in asterisk form includes the
value '*' for the ":path" pseudo-header field.
This pseudo-header field MUST NOT be empty for "http" or "https"
URIs; "http" or "https" URIs that do not contain a path component
MUST include a value of '/'. The exception to this rule is an
OPTIONS request for an "http" or "https" URI that does not include
a path component; these MUST include a ":path" pseudo-header field
with a value of '*' (see [[RFC7230], Section 5.3.4](https://datatracker.ietf.org/doc/html/rfc7230#section-5.3.4)).
Belshe, et al. Standards Track [Page 55]
RFC 7540 HTTP/2 May 2015
All HTTP/2 requests MUST include exactly one valid value for the
":method", ":scheme", and ":path" pseudo-header fields, unless it is
a CONNECT request (Section 8.3). An HTTP request that omits
mandatory pseudo-header fields is malformed (Section 8.1.2.6).
HTTP/2 does not define a way to carry the version identifier that is
included in the HTTP/1.1 request line.
|
There is also #961 |
c7ae010 to
a0f6379
Compare
53c8772 to
4696e75
Compare
|
Rebased and will update the comments too. |
4696e75 to
bad9ff0
Compare
|
based on #961 |
|
Isn't the main reason for this PR is to fix this test: "handle a ':path' with an asterisk" |
jrudolph
left a comment
There was a problem hiding this comment.
Not sure how important these changes are. CONNECT is not really supported (afair), so I'm somewhat reluctant changing behaviour and adding extra code for that.
The OPTIONS change seems like a thing that might be needed (though, it's somewhat weird that no one found it missing so far). It doesn't feel fully addressed, though, tests and demonstrations how to use it are missing.
In any case, these should be two separate PRs, but right now I'm not convinced any of these are changes we should do.
bad9ff0 to
7dea820
Compare
7dea820 to
b0edc50
Compare
Motivation: HTTP/2 applications need to distinguish a server-wide OPTIONS request from OPTIONS on the root resource. Modification: Preserve the scheme and authority and expose the asterisk using the existing Raw-Request-URI marker. Document how Scala and Java handlers can read it. Cover both targets in the same HTTP/2 server test. Result: Application handlers can recognize server-wide OPTIONS while OPTIONS / keeps its existing URI and does not gain the marker. Tests: One focused Http2ServerSpec case (two requests) and two focused RequestParsingSpec cases passed on Scala 2.13.18 / Temurin 17.0.21.1. The http2-tests/Test and http-core Scalafmt checks and git diff --check passed. References: RFC 9113 section 8.3.1; apache#981.
b0edc50 to
b9ef4ef
Compare
pjfanning
left a comment
There was a problem hiding this comment.
Thanks for picking up the asterisk-form TODO. Accepting OPTIONS * on HTTP/2 is right per RFC 9113 §8.3.1, and rejecting * for other methods is a good guard. My concerns are about how the request is then presented to existing handlers, see inline. The first two are the ones I'd like to settle before this goes in.
| ":scheme" -> "http", | ||
| ":path" -> "*")) | ||
| request.uri.toString should ===("*") // FIXME: Compare in a better way | ||
| "handle server-wide OPTIONS with an application-visible asterisk target" in { |
There was a problem hiding this comment.
The accepting cases are covered, but the new rejection paths aren't. Could tests be added that GET with :path: * (and HEAD with transparent-head-requests on, since the check uses method rather than effectiveMethod) is answered with a 400 naming :path, and that *?q, */x and ** are rejected by the new grammar alternative?
b9ef4ef to
5198420
Compare
5198420 to
3988aec
Compare
pjfanning
left a comment
There was a problem hiding this comment.
Thanks, the opt-in setting and the attribute instead of a synthetic Raw-Request-URI header resolve my two blocking points. What is left:
- Rejection-path tests (from the earlier comment on
RequestParsingSpec). The only new negative test is "disabled by default". With the setting on, could we cover GET with:path: *, HEAD withtransparent-head-requests, and*?q,*/xand**? As far as I can see the grammar and the match inRequestParsingreject all of them, so these should just pin it. - Where the flag is stored. It is kept by wrapping the
internalSettingsslot in a privateAsteriskOptionsEnabledcase class, with the constructor parameter renamed tostoredInternalSettings. It works and the test shows it surviveswithInternalSettings, but it leaks intotoString/equalsand is easy to break later.Http2ServerSettingsImplisprivate[http], so could this be a normal field with MiMa filters for the impl's constructor andcopy? - No programmatic API.
acceptAsteriskOptionsisprivate[http]and there is nowithAcceptAsteriskOptionson the scaladsl or javadslHttp2ServerSettings, unlike the other HTTP/2 settings, so it can only be enabled through config. Was that intended? - Nit: the title says
fix, but this now adds a setting and a public attribute key, sofeatfits better, and the newAttributeKeys.asteriskRequestTarget(Scala and Java) could carry a@since. - Nit: the attribute is a
Stringwhose only possible value is"*". Fine if you want room for other targets later, otherwise a marker would be simpler.
Motivation: Applications need to distinguish server-wide OPTIONS from the root resource without changing the behavior of existing routes or forwarding a synthetic header. Applications using programmatic settings also need the same explicit opt-in as applications using HOCON. Modification: Add a default-off HTTP/2 server setting and expose its Java and Scala accessors. Store the Boolean separately from internal settings. When enabled, retain the effective URI and expose the original asterisk through the typed request attribute. Leave HTTP/1.1 and CONNECT unchanged. Document the API and exclude only the two former generated signatures of the internal implementation from MiMa. Result: Applications can enable the setting per server without disturbing internal settings. Rewritten requests still select their outbound URI. The previous public settings method descriptors are unchanged. Tests: JDK 17 and Scala 2.13.18: Http2ServerSettingsSpec, 14 tests passed. JDK 17: http-core compiled and MiMa passed on Scala 2.13.18 and 3.3.9. Scoped Scala/Java formatting, headers and diff whitespace check passed. No new wire tests were added or run in this settings-only follow-up. References: RFC 9113 section 8.3.1 and RFC 9110 section 9.3.7.
3988aec to
858c650
Compare
Motivation
HTTP/2 applications need to distinguish a server-wide
OPTIONS *request fromOPTIONS /without changing the default routing behavior or interfering with outbound URI rewriting.Modification
Add the default-off
pekko.http.server.http2.accept-asterisk-optionssetting. When enabled, retain the effective URI's scheme and authority and expose*in the typed request attributeAttributeKeys.asteriskRequestTargetin Scala and Java, instead of adding a syntheticRaw-Request-URIheader. Document the HTTP/2 opt-in and the existing HTTP/1.1 behavior. Ordinary path parsing and CONNECT handling are unchanged.Result
Without opt-in, an HTTP/2 server continues rejecting
OPTIONS *. With opt-in, application handlers can distinguish it fromOPTIONS /. The attribute is not written to the wire and does not override a rewritten outbound URI. HTTP/1.1 wire and request-model behavior remain unchanged.Tests
git diff --checkpassed. Independent review of the exact code diff found no blocking issue.References