GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||
GeezerVison is showing github.com — Return null or the default from getTimeMillis() for invalid dates by CCCLL · Pull Request #17965 · netty/netty Conversation
Contributor
Motivation:
For example, a handler that calls This was fixed on the old Netty 5 branch in #11853 but never made it to 4.x. Modification: Port #11853: throw the unchecked Result:
Before: After: The new assertions fail before the change.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
normanmaurer
added a commit
that referenced
this pull request
…17967) Motivation: `HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters of `Headers`, are documented to return `null`, and the overloads with a default value the default value, when the header value can't be converted. `DefaultHeaders` catches conversion failures since #7710, but `ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and `ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`, `getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let the `NumberFormatException`, or the `IndexOutOfBoundsException` of `getChar(...)` for an empty value, escape to the caller. For example, `HttpToHttp2ConnectionHandler` reads `x-http2-stream-weight` with `getShort(name, defaultValue)`. A request with `x-http2-stream-weight: high` is written with the default weight when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the write fails with a `NumberFormatException` and the handler sends GOAWAY. Modification: Catch `RuntimeException` around the conversion in these getters, like `DefaultHeaders` does. `getTimeMillis(...)` is covered by #17965. Add tests for values that can't be converted. Result: The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return `null` or the default value for a value that can't be converted, like `DefaultHttpHeaders` and `DefaultHttp2Headers`. Headers `x-count: abc` and `x-empty:` (empty value); `DefaultHttpHeaders` and `DefaultHttp2Headers` return `null` or `-1` for all of these. Then a request with `x-http2-stream-weight: high` written through `HttpToHttp2ConnectionHandler`: Before: ``` ReadOnlyHttpHeaders.getInt(x-count, -1) threw java.lang.NumberFormatException: For input string: "abc" ReadOnlyHttpHeaders.getShort(x-count) threw java.lang.NumberFormatException: For input string: "abc" ReadOnlyHttp2Headers.getChar(x-empty) threw java.lang.IndexOutOfBoundsException: index: 0 must be in the range [0,0) ReadOnlyHttp2Headers.getLong(x-count) threw java.lang.NumberFormatException: abc ReadOnlyHttp2Headers.getDouble(x-count, -1) threw java.lang.NumberFormatException: For input string: "abc" HttpToHttp2ConnectionHandler write with DefaultHttpHeaders: success=true, first outbound frame type=1 (HEADERS) HttpToHttp2ConnectionHandler write with ReadOnlyHttpHeaders: success=false cause=java.lang.NumberFormatException: For input string: "high", first outbound frame type=7 (GOAWAY) ``` After: ``` ReadOnlyHttpHeaders.getInt(x-count, -1) = -1 ReadOnlyHttpHeaders.getShort(x-count) = null ReadOnlyHttp2Headers.getChar(x-empty) = null ReadOnlyHttp2Headers.getLong(x-count) = null ReadOnlyHttp2Headers.getDouble(x-count, -1) = -1.0 HttpToHttp2ConnectionHandler write with DefaultHttpHeaders: success=true, first outbound frame type=1 (HEADERS) HttpToHttp2ConnectionHandler write with ReadOnlyHttpHeaders: success=true, first outbound frame type=1 (HEADERS) ``` The new tests fail before the change. `codec-http` and `codec-http2` tests pass. --------- Co-authored-by: Norman Maurer <[email protected]>
This was referenced
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Motivation: Headers.getTimeMillis(name) is documented to return null, and getTimeMillis(name, defaultValue) the default value, when the header value is not a date. CharSequenceValueConverter.convertToTimeMillis(...) reports an unparsable value by throwing a java.text.ParseException through PlatformDependent.throwException(...), although the method does not declare it. DefaultHeaders.getTimeMillis(...) only catches RuntimeException, so the checked exception escapes to the caller, and ReadOnlyHttpHeaders and ReadOnlyHttp2Headers call the converter without catching anything. For example, a handler that calls request.headers().getTimeMillis(IF_MODIFIED_SINCE, -1) for a request with "If-Modified-Since: yesterday" gets a ParseException in exceptionCaught(...) instead of -1. DefaultHttpHeaders, DefaultHttp2Headers and the read-only headers all behave like this. This was fixed on the old Netty 5 branch in netty#11853 but never made it to 4.x. Modification: Port netty#11853: throw the unchecked DateTimeParseException from convertToTimeMillis(...), and catch RuntimeException in the getTimeMillis(...) methods of ReadOnlyHttpHeaders and ReadOnlyHttp2Headers like DefaultHeaders does. Add tests for values that are not dates. Result: getTimeMillis(...) and getTimeMillisAndRemove(...) return null or the default value for a header that is not a date, as documented. Code that calls convertToTimeMillis(...) directly now gets a DateTimeParseException instead of an undeclared ParseException.
CCCLL
force-pushed
the
header-time-millis-parse-exception
branch
from
ab6a6fa to
67503fc
Compare
normanmaurer
added a commit
that referenced
this pull request
…invalid values (#18021) Auto-port of #17967 to 5.0 Cherry-picked commit: 5f89d65 --- Motivation: `HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters of `Headers`, are documented to return `null`, and the overloads with a default value the default value, when the header value can't be converted. `DefaultHeaders` catches conversion failures since #7710, but `ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and `ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`, `getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let the `NumberFormatException`, or the `IndexOutOfBoundsException` of `getChar(...)` for an empty value, escape to the caller. For example, `HttpToHttp2ConnectionHandler` reads `x-http2-stream-weight` with `getShort(name, defaultValue)`. A request with `x-http2-stream-weight: high` is written with the default weight when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the write fails with a `NumberFormatException` and the handler sends GOAWAY. Modification: Catch `RuntimeException` around the conversion in these getters, like `DefaultHeaders` does. `getTimeMillis(...)` is covered by #17965. Add tests for values that can't be converted. Result: The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return `null` or the default value for a value that can't be converted, like `DefaultHttpHeaders` and `DefaultHttp2Headers`. Co-authored-by: CCCLL <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
normanmaurer
added a commit
that referenced
this pull request
…invalid values (#18017) Auto-port of #17967 to 4.1 Cherry-picked commit: 5f89d65 --- Motivation: `HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters of `Headers`, are documented to return `null`, and the overloads with a default value the default value, when the header value can't be converted. `DefaultHeaders` catches conversion failures since #7710, but `ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and `ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`, `getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let the `NumberFormatException`, or the `IndexOutOfBoundsException` of `getChar(...)` for an empty value, escape to the caller. For example, `HttpToHttp2ConnectionHandler` reads `x-http2-stream-weight` with `getShort(name, defaultValue)`. A request with `x-http2-stream-weight: high` is written with the default weight when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the write fails with a `NumberFormatException` and the handler sends GOAWAY. Modification: Catch `RuntimeException` around the conversion in these getters, like `DefaultHeaders` does. `getTimeMillis(...)` is covered by #17965. Add tests for values that can't be converted. Result: The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return `null` or the default value for a value that can't be converted, like `DefaultHttpHeaders` and `DefaultHttp2Headers`. Co-authored-by: CCCLL <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
|
There was an error while loading. Please reload this page.
🚨 TestLens detected 2 failed tests 🚨Test SummaryTip Inspect all details with the TestLens CLI: Build PR / linux-x86_64-java11 build > Netty/Codec/HTTP2
Build PR / windows-x86_64-java11-boringssl > Netty/Codec/HTTP
🏷️ Commit: 67503fc Test FailuresHttp2MultiplexTransportTest (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java11 build)WebSocketHandshakeHandOverTest > testClientHandshakerForceClose() (Netty/Codec/HTTP in Build PR / windows-x86_64-java11-boringssl)
Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…invalid values (netty#18017) Auto-port of netty#17967 to 4.1 Cherry-picked commit: 5f89d65 --- Motivation: `HttpHeaders.getInt(name)` and `getShort(name)`, and the typed getters of `Headers`, are documented to return `null`, and the overloads with a default value the default value, when the header value can't be converted. `DefaultHeaders` catches conversion failures since netty#7710, but `ReadOnlyHttpHeaders.getInt(...)` and `getShort(...)`, and `ReadOnlyHttp2Headers.getByte(...)`, `getChar(...)`, `getShort(...)`, `getInt(...)`, `getLong(...)`, `getFloat(...)` and `getDouble(...)` let the `NumberFormatException`, or the `IndexOutOfBoundsException` of `getChar(...)` for an empty value, escape to the caller. For example, `HttpToHttp2ConnectionHandler` reads `x-http2-stream-weight` with `getShort(name, defaultValue)`. A request with `x-http2-stream-weight: high` is written with the default weight when it uses `DefaultHttpHeaders`, but with `ReadOnlyHttpHeaders` the write fails with a `NumberFormatException` and the handler sends GOAWAY. Modification: Catch `RuntimeException` around the conversion in these getters, like `DefaultHeaders` does. `getTimeMillis(...)` is covered by netty#17965. Add tests for values that can't be converted. Result: The getters of `ReadOnlyHttpHeaders` and `ReadOnlyHttp2Headers` return `null` or the default value for a value that can't be converted, like `DefaultHttpHeaders` and `DefaultHttp2Headers`. Co-authored-by: CCCLL <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
|
@normanmaurer I rebased this onto 4.2 right after your comment and added a commit that renames the caught exceptions to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.