Query params: parse and store separately in HttpRequest#105
Query params: parse and store separately in HttpRequest#105Ericthilen wants to merge 3 commits intomainfrom
Conversation
📝 WalkthroughWalkthroughConnectionHandler now extracts the request path and parses URL-decoded query parameters, passes them into HttpRequest, and captures client IP as a request attribute. HttpRequest gains a new queryParams field, constructors that accept query parameters, and getters to access them. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/main/java/org/example/ConnectionHandler.java`:
- Around line 117-121: The extractPath method returns an empty string for URIs
like "?a=1" — update extractPath to normalize an empty path to "/" by returning
"/" when uri has no path before the '?' (i.e., if substring(0, q) yields empty).
Also update the query-parsing logic referenced around lines 135-143 (the loop
that splits on '&' into segments) to skip empty segments and ignore empty keys
(continue when segment is empty or when key length==0 after splitting on '='),
so consecutive separators like "&&" or leading '&' don't produce empty-key
params; apply these checks in the query parsing routine that iterates over
segments.
- Around line 123-160: parseQueryParams currently calls
URLDecoder.decode(key/value) which can throw IllegalArgumentException on
malformed percent-encoding; wrap the call to parseQueryParams(...) inside the
request handling path (the method that calls parseQueryParams in
ConnectionHandler) with a try-catch that catches IllegalArgumentException and
returns a controlled 400 Bad Request response. Alternatively, modify
parseQueryParams itself to catch IllegalArgumentException around
URLDecoder.decode and rethrow a specific checked exception (or return an error
indicator) so the caller can map it to a 400; reference URLDecoder.decode and
parseQueryParams when making the change.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/java/org/example/ConnectionHandler.javasrc/main/java/org/example/httpparser/HttpRequest.java
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/java/org/example/ConnectionHandler.java (1)
147-161: Consider skipping empty keys after decoding.Empty pairs are correctly skipped, but a query like
?=valuewill produce an entry with an empty-string key. Consider also skipping entries where the key is empty after URL decoding.Suggested enhancement
key = URLDecoder.decode(key, StandardCharsets.UTF_8); value = URLDecoder.decode(value, StandardCharsets.UTF_8); + if (key.isEmpty()) { + start = ampIndex + 1; + continue; + } + params.computeIfAbsent(key, k -> new ArrayList<>()).add(value);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/example/ConnectionHandler.java` around lines 147 - 161, The parsing currently accepts a pair like "?=value" because it checks pair.isEmpty() but not whether the decoded key is empty; in ConnectionHandler (the query-pair loop using variables pair, equalsIndex, key, value, ampIndex, start) extract the raw key and raw value as you already do, then URL-decode the key (and decode the value) using the same decoder used elsewhere (e.g., URLDecoder with UTF-8), and if the decoded key is empty do a continue to skip the entry; replace any subsequent use of key/value with the decoded versions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/main/java/org/example/ConnectionHandler.java`:
- Around line 147-161: The parsing currently accepts a pair like "?=value"
because it checks pair.isEmpty() but not whether the decoded key is empty; in
ConnectionHandler (the query-pair loop using variables pair, equalsIndex, key,
value, ampIndex, start) extract the raw key and raw value as you already do,
then URL-decode the key (and decode the value) using the same decoder used
elsewhere (e.g., URLDecoder with UTF-8), and if the decoded key is empty do a
continue to skip the entry; replace any subsequent use of key/value with the
decoded versions.
alicewersen-rgb
left a comment
There was a problem hiding this comment.
Looking good! The code is clean, simple and the comments explain the logic well.
EdvinSandgren
left a comment
There was a problem hiding this comment.
I agree with the previous review, looks good.
Fixes #102
Summary by CodeRabbit