Skip to content

Commit eb371a9

Browse files
clems71lammel
andauthored
Adding support for HEAD method query params binding (#2027)
* Adding support for HEAD method query params binding. * Update comment for added HEAD method for bind Co-authored-by: Roland Lammel <[email protected]>
1 parent db9c708 commit eb371a9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

bind.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
111111
if err := b.BindPathParams(c, i); err != nil {
112112
return err
113113
}
114-
// Issue #1670 - Query params are binded only for GET/DELETE and NOT for usual request with body (POST/PUT/PATCH)
115-
// Reasoning here is that parameters in query and bind destination struct could have UNEXPECTED matches and results due that.
116-
// i.e. is `&id=1&lang=en` from URL same as `{"id":100,"lang":"de"}` request body and which one should have priority when binding.
117-
// This HTTP method check restores pre v4.1.11 behavior and avoids different problems when query is mixed with body
118-
if c.Request().Method == http.MethodGet || c.Request().Method == http.MethodDelete {
114+
// Only bind query parameters for GET/DELETE/HEAD to avoid unexpected behavior with destination struct binding from body.
115+
// For example a request URL `&id=1&lang=en` with body `{"id":100,"lang":"de"}` would lead to precedence issues.
116+
// The HTTP method check restores pre-v4.1.11 behavior to avoid these problems (see issue #1670)
117+
method := c.Request().Method
118+
if method == http.MethodGet || method == http.MethodDelete || method == http.MethodHead {
119119
if err = b.BindQueryParams(c, i); err != nil {
120120
return err
121121
}

0 commit comments

Comments
 (0)