httparty
httparty copied to clipboard
Cookies are not set properly after a redirect follow
Test request:
curl --location --request POST 'https://www.sainsburys.co.uk/shop/ShoppingListDisplay' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'shoppingList=RICE' \
--data-urlencode 'action=findProducts' \
--data-urlencode 'langId=44' \
--data-urlencode 'storeId=10151' \
--data-urlencode 'catalogueId=10241'
Expected result: HTTP 200 after 1 redirect. Actual result: HTTP 403 ERROR after 1 redirect.
After running the HTTParty requests through Fiddler I discovered it is sending maligned cookies. First call that responds with a redirect sets the following cookies:
HTTParty follows the redirect and issues a GET request with the following cookies though:
For comparison, the same request executed via Postman results in the following set of cookies:
Seems like something goes wrong when the cookies are parsed from the first response. There is another issue open that talks about cookie parsing, perhaps it is time to look at these. I would have submitted a PR but this is my third week learning Ruby and Rails so you really wouldn't want to see my code! :)
NB: Should you also drop the Content-Type
header when you follow a redirect using GET after an initial POST request?
Great library otherwise, thanks!