Skip to content

Commit

Permalink
Add query strings in order
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Jun 23, 2021
1 parent 544a9f9 commit 89e85c1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions coap_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,12 @@ func (co *CoAPHTTP) HTTPRequestToCoAP(req *http.Request, doFn func(*pool.Message
msg.SetToken(co.NextToken())
msg.SetCode(code)
msg.SetPath(co.Paths.HTTPPathToCoapPath(req.URL.Path))
queries := req.URL.Query()
for k, vs := range queries {
for _, v := range vs {
msg.AddQuery(k + "=" + v)
}
// We have to use req.URL.RawQuery here to ensure that the
// query options get added to the message in order. Using
// req.URL.Query() returns them in a map which loses the
// ordering.
for _, q := range strings.Split(req.URL.RawQuery, "&") {
msg.AddQuery(q)
}
if req.Body != nil {
body, err := ioutil.ReadAll(req.Body)
Expand Down

0 comments on commit 89e85c1

Please sign in to comment.