Skip to content

Commit

Permalink
Use QueryString while constructing RequestURI instead of QueryArgs if…
Browse files Browse the repository at this point in the history
… parsedQueryArgs is set to false (valyala#937)
  • Loading branch information
anshul-jain-aws authored Jan 2, 2021
1 parent 245e7ec commit 6234776
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (u *URI) RequestURI() []byte {
} else {
dst = appendQuotedPath(u.requestURI[:0], u.Path())
}
if u.queryArgs.Len() > 0 {
if u.parsedQueryArgs && u.queryArgs.Len() > 0 {
dst = append(dst, '?')
dst = u.queryArgs.AppendBytes(dst)
} else if len(u.queryString) > 0 {
Expand Down
12 changes: 12 additions & 0 deletions uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,15 @@ func testURIParse(t *testing.T, u *URI, host, uri,
t.Fatalf("Unexpected hash %q. Expected %q. host=%q, uri=%q", u.Hash(), expectedHash, host, uri)
}
}

func TestURIWithQuerystringOverride(t *testing.T) {
var u URI
u.SetQueryString("q1=foo&q2=bar")
u.QueryArgs().Add("q3", "baz")
u.SetQueryString("q1=foo&q2=bar&q4=quux")
uriString := string(u.RequestURI())

if uriString != "/?q1=foo&q2=bar&q4=quux" {
t.Fatalf("Expected Querystring to be overriden but was %s ", uriString)
}
}

0 comments on commit 6234776

Please sign in to comment.