Repository navigation
fix(tool/http): skip optional header params that were not provided - #4335
beskvladimir-create wants to merge 9 commits into
Conversation
Add a unit test for getHeaders that builds paramsMap through ParseParams and covers an optional header param that is omitted and one that is provided.
ParseParams appends a ParamValue for every declared parameter, so an optional header param that the caller omits reaches getHeaders as a nil entry in paramsMap. getHeaders only checked key presence and then failed the nil to string assertion, so every invocation that omitted an optional header returned an error. Skip nil header values, matching how getURL already treats optional query params.
There was a problem hiding this comment.
Code Review
This pull request modifies the getHeaders function in internal/tools/http/http.go to omit optional header parameters that are present in the parameters map with a nil value. Additionally, a new test file internal/tools/http/http_headers_test.go is added to verify this behavior with unit tests. There are no review comments, so I have no feedback to provide.
Yuan325
left a comment
There was a problem hiding this comment.
Thank you for your contributions @beskvladimir-create Will approve once feedback is addressed.
Yuan325
left a comment
There was a problem hiding this comment.
Thank you. I've added a test case to make sure value with empty string is also filtered.
|
/gcbrun |
|
/gcbrun |
|
Hi @beskvladimir-create The unit tests is failing for another test case, can you please take a look at that. And also, should we be filtering empty string values too? Seems like the test case that I added was failing. Thank you again for your contributions! |
An empty string header value is now omitted, so a source or tool header with the same name is kept, as suggested in review.
… params A nil value (optional header param not provided) and an empty string are now skipped and keep the static header; a non-string value still returns an error.
|
Thanks @Yuan325! Both failures came from the same change, and I've pushed two commits to address them:
I couldn't run the Go test suite locally (no Go 1.27 toolchain in my environment); I checked the new |
Description
getHeadersfailed whenever an optional header param was omitted.ParseParamsappends aParamValuefor every declared parameter, so the omitted param reachesgetHeadersas a nil entry inparamsMap; the code only checked key presence and then failed thenil.(string)assertion, returning "error populating request headers" for every such call.This change skips nil header values, matching how
getURLalready treats optional query params. A unit test (http_headers_test.go) buildsparamsMapthroughParseParams, asInvokedoes, and covers both the omitted and the provided case.Note: open PR #3472 touches the adjacent
elseline (%t→%T); this PR does not change that line, so the two do not overlap in intent.Security: header values are still taken only from declared parameters; no new input path is added.
Testing: I could not run
go testlocally (my environment cannot download the Go 1.25.8 toolchain); the change isgofmt-clean and CI will run the tests.PR Checklist
!if this involve a breaking change (not breaking)🛠️ Fixes #4334