Skip to content

Commit

Permalink
nub the query parameters (keep the first occurrence)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbiehl committed Feb 9, 2024
1 parent 48ec532 commit edfb4d7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions scarf-gateway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ library
, bytestring
, case-insensitive
, conduit
, containers
, cryptohash-sha256
, exceptions
, hashable
Expand Down
3 changes: 2 additions & 1 deletion src/Scarf/Gateway/Rule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Data.ByteString.Base64.URL (encode)
import Data.ByteString.Builder (Builder, char7, string7, toLazyByteString)
import Data.ByteString.Char8 qualified as BS
import Data.ByteString.Lazy qualified as LBS
import Data.Containers.ListUtils (nubOrdOn)
import Data.HashMap.Strict (HashMap)
import Data.HashMap.Strict qualified as HashMap
import Data.HashSet (HashSet)
Expand Down Expand Up @@ -665,7 +666,7 @@ rewriteQueryString redirectTarget request
-- times -- after all, query strings may contain more than one occurrence of
-- a variable.
combinedQuery =
redirectTargetQuery <> requestQuery
nubOrdOn fst (redirectTargetQuery <> requestQuery)

renderedQuery =
Text.decodeUtf8
Expand Down
4 changes: 2 additions & 2 deletions test/golden/file-package-with-variables-1.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ capture: |-
FlatfileCapture
{ fileAbsoluteUrl =
Just
"https://datausa.io/api/data?drilldowns=Nation&measures=Population&drilldowns=Nation&measures=Population"
"https://datausa.io/api/data?drilldowns=Nation&measures=Population"
, fileVariables =
fromList
[ ( "drilldowns" , "Nation" ) , ( "measures" , "Population" ) ]
, filePackage = "a1b331fa-1539-49e5-bdc4-dc8a48e586d1"
}
headers:
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population&drilldowns=Nation&measures=Population
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population
query: ?drilldowns=Nation&measures=Population
status: 302
4 changes: 2 additions & 2 deletions test/golden/file-package-with-variables-2.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ capture: |-
FlatfileCapture
{ fileAbsoluteUrl =
Just
"https://datausa.io/api/data?drilldowns=Nation&measures=Population&measures=Population"
"https://datausa.io/api/data?drilldowns=Nation&measures=Population"
, fileVariables =
fromList
[ ( "drilldowns" , "Nation" ) , ( "measures" , "Population" ) ]
, filePackage = "a1b331fa-1539-49e5-bdc4-dc8a48e586d1"
}
headers:
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population&measures=Population
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population
query: ?measures=Population
status: 302
4 changes: 2 additions & 2 deletions test/golden/file-package-without-varible-1.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ capture: |-
FlatfileCapture
{ fileAbsoluteUrl =
Just
"https://datausa.io/api/data?drilldowns=Nation&measures=Population&drilldowns=Nation&measures=Population"
"https://datausa.io/api/data?drilldowns=Nation&measures=Population"
, fileVariables = fromList []
, filePackage = "a1b331fa-1539-49e5-bdc4-dc8a48e586d1"
}
headers:
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population&drilldowns=Nation&measures=Population
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population
query: ?drilldowns=Nation&measures=Population
status: 302
4 changes: 2 additions & 2 deletions test/golden/file-package-without-varible-2.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ capture: |-
FlatfileCapture
{ fileAbsoluteUrl =
Just
"https://datausa.io/api/data?drilldowns=Nation&measures=Population&drilldowns=Nation&measures=Population"
"https://datausa.io/api/data?drilldowns=Nation&measures=Population"
, fileVariables = fromList []
, filePackage = "a1b331fa-1539-49e5-bdc4-dc8a48e586d1"
}
headers:
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population&drilldowns=Nation&measures=Population
Location: https://datausa.io/api/data?drilldowns=Nation&measures=Population
query: ?drilldowns=Nation&measures=Population
status: 302

0 comments on commit edfb4d7

Please sign in to comment.