Repository navigation
Conversation
…utStream.read in ServletHttpRequestAdapter Fix three bugs in ServletHttpRequestAdapter (and its generated Jakarta Servlet counterpart): 1. getRemoteHost() returned String.valueOf(remotePort()) instead of remoteHost(). 2. getRequestURL() appended ":-1" when the Host/:authority header omitted an explicit port (DefaultHttpRequest.serverPort() returns -1). Guard port appending with port > 0. 3. HttpInputStream overrode ServletInputStream.readLine(byte[], int, int) with is.read(b, off, len) instead of overriding read(byte[], int, int), breaking ServletInputStream's newline-delimited readLine() behavior and leaving offset reads un-delegated. Add unit tests in ServletHttpRequestAdapterTest covering all three fixes. Signed-off-by: flush921 <1366412595@qq.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16599 +/- ##
============================================
- Coverage 61.24% 59.28% -1.96%
+ Complexity 11763 15 -11748
============================================
Files 1953 1953
Lines 89411 89418 +7
Branches 13502 13505 +3
============================================
- Hits 54757 53009 -1748
- Misses 29031 30668 +1637
- Partials 5623 5741 +118
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
EarthChen
left a comment
There was a problem hiding this comment.
Verified locally — the three fixes are real and correct. On base d809bb1, 5 of 10 tests fail with exactly the claimed mechanisms (getRemoteHost() returned "54321"; getRequestURL() produced "http://example.com:-1/orders/1"; readLine() consumed "first\nsecond\n" as 13 bytes and read(byte[], int, int) fell back to InputStream's single-byte loop). On this PR head all 10 pass, and the JDK-17-generated Jakarta variant in the same module carries the same fixes. Also confirmed that javax.servlet-api 4.0.1's ServletInputStream.readLine(byte[], int, int) has a concrete spec-default implementation (byte-by-byte until '\n'), so removing the wrong override restores spec behavior rather than breaking anything.
One remaining spec deviation in the same adapter — could we fix it in this PR too?
getServerPort() still returns -1 when the Host header omits the port. Within dubbo's http12 core, -1 is an established "unspecified" sentinel — CorsHeaderFilter.getPort() normalizes it to 80/443 by scheme — but this adapter is the Servlet spec boundary: downstream servlet code calling getServerPort() has no visibility into that internal convention, and the Servlet spec says the port defaults to 80/443. Suggest mirroring CorsHeaderFilter's normalization in ServletHttpRequestAdapter.getServerPort() (return 80 for http / 443 for https when serverPort() < 0). That leaves dubbo-remoting-http12 untouched, keeps the CORS comparison identical (getPort(-1) == getPort(80)), and makes the adapter spec-conformant end to end — at which point the port > 0 guard added in getRequestURL() becomes unreachable for http/https and can be simplified accordingly. A getServerPort() column in the existing @CsvSource test would pin it down.
…er.getServerPort() Mirror CorsHeaderFilter.getPort() in ServletHttpRequestAdapter.getServerPort() by returning 80 for http and 443 for https when serverPort() < 0, simplify the now-redundant port > 0 check in getRequestURL(), and assert getServerPort() in the parameterized test. Signed-off-by: flush921 <1366412595@qq.com>
|
Thanks @EarthChen for the thorough review and great suggestion! Updated in the latest commit:
Spotless, checkstyle, Jakarta source generation, and all 10 tests pass locally. |
What is the purpose of the change?
Fix three bugs in
ServletHttpRequestAdapter(and its generated Jakarta Servlet counterpart indubbo-triple-servlet):getRemoteHost()returned the remote port instead of the host:getRemoteHost()calledString.valueOf(remotePort())instead ofremoteHost(), returning e.g."54321"instead of the peer host name/address.getRequestURL()appended: -1when no port is specified inHost/:authority:DefaultHttpRequest.serverPort()returns-1when theHostheader omits a port (as verified inDefaultHttpRequestTest.parsesHostAuthority), soport != 80/port != 443evaluated totrueand produced URLs likehttp://example.com:-1/orders/1. Guarding withport > 0omits unspecified ports while keeping non-default ports.HttpInputStreamoverrodereadLine(byte[], int, int)instead ofread(byte[], int, int): OverridingServletInputStream.readLine(byte[], int, int)withis.read(b, off, len)bypassed the Servlet specification's newline-delimitedreadLine()implementation (reading across multiple lines) and left bulk offset reads (read(byte[], int, int)) falling back toInputStream's single-byte loop. Replacing the override withread(byte[], int, int)fixes both.Verification
ServletHttpRequestAdapterTestbefore the fix../mvnw test -pl dubbo-plugin/dubbo-triple-servlet -am -Dtest=ServletHttpRequestAdapterTest,ServletHttpResponseAdapterTest -Dsurefire.failIfNoSpecifiedTests=false(includingspotless:check,checkstyle, and JDK 17 Jakarta source generation): 13/13 tests pass.Checklist