Skip to content

Commit

Permalink
SignedQuery should respect explicity body and content-type choices
Browse files Browse the repository at this point in the history
A PostQuery used to override any explicityly given Body and
Content-Type choices in the SignedQuery. I belive this is to be
erroneous, as it simply overrode explicit selections due to a
PostQuery, which is particularly impossible to deal with when
implementing AWS version 4 signing.

It now enforces the PostQuery defaults *only* if the explicit
selections are missing.
  • Loading branch information
ozataman committed Mar 1, 2013
1 parent ba2a2b4 commit 1426408
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Aws/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,31 @@ queryToHttpRequest SignedQuery{..}
, fmap (\auth -> ("Authorization", auth)) sqAuthorization]
++ sqAmzHeaders
++ sqOtherHeaders
, HTTP.requestBody = case sqMethod of
PostQuery -> HTTP.RequestBodyLBS . Blaze.toLazyByteString $ HTTP.renderQueryBuilder False sqQuery
_ -> case sqBody of
Nothing -> HTTP.RequestBodyBuilder 0 mempty
Just x -> x
, HTTP.requestBody =

-- | An explicityly defined body parameter should overwrite everything else.
case sqBody of
Just x -> x
Nothing ->
-- | a POST query should convert its query string into the body
case sqMethod of
PostQuery -> HTTP.RequestBodyLBS . Blaze.toLazyByteString $
HTTP.renderQueryBuilder False sqQuery
_ -> HTTP.RequestBodyBuilder 0 mempty

, HTTP.decompress = HTTP.alwaysDecompress
#if MIN_VERSION_http_conduit(1, 9, 0)
, HTTP.checkStatus = \_ _ _ -> Nothing
#else
, HTTP.checkStatus = \_ _ -> Nothing
#endif
}
where contentType = case sqMethod of
PostQuery -> Just "application/x-www-form-urlencoded; charset=utf-8"
_ -> sqContentType
where
-- | An explicitly defined content-type should override everything else.
contentType = sqContentType `mplus` defContentType
defContentType = case sqMethod of
PostQuery -> Just "application/x-www-form-urlencoded; charset=utf-8"
_ -> Nothing

-- | Create a URI fro a 'SignedQuery' object.
--
Expand Down

0 comments on commit 1426408

Please sign in to comment.