From 67c5f1c5410e9bb523c0f2486e58b2174e13d3d2 Mon Sep 17 00:00:00 2001 From: kaishi05 Date: Sat, 11 Oct 2025 10:48:00 -0700 Subject: [PATCH] Reset queryParameterString when the current session doesn't have a query. In HTTP 1.1, connection is reused across HTTP connection (aka HTTP session in nanohttpd). See the connection reuse codes in ClientHandler where HTTPSession is reused by calling execute() in a while loop. However, in HTTPSession, queryParameterString is not cleaned up correctly across sessions when a previous session has a query while the current one doesn't have a query. This results in the incorrect caching of queryParameterString. The fix is to ensure queryParameterString is initialized to an empty string when the current session's URI does not contain a query component. The bug is reproduced with nanohttpd + okhttp which is also used to validate the fix. --- core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java b/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java index 80456b06..28270423 100644 --- a/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java +++ b/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java @@ -158,6 +158,7 @@ private void decodeHeader(BufferedReader in, Map pre, Map