needle icon indicating copy to clipboard operation
needle copied to clipboard

Issue setting cookies on POST request using needle Promise

Open Nathan-Nesbitt opened this issue 4 years ago • 1 comments

Issue

I am currently trying to send a post request to an endpoint using needle. When I try to append the cookies to the request it sends the cookies in the body instead of setting them in the request headers which is strange, as I can do this without issue when sending them using a GET request. The following is what the output on the server looks like:

body: [Object: null prototype] {
    'cookies[token]': '[The token I sent to the endpoint]'
}

Code to Reproduce

The following are multiple ways that I tried to send the cookies, all of which send them in the body:

Following the get request syntax

This works when sending a get request instead of a post request.

needle(
        method="post",
        url=login_server,
        headers={cookies: {token: req.cookies.token}}
    )

Following the docs suggested format

This is how the docs say to send the request.

needle(
        method="post",
        data="",
        url=login_server,
        options={headers: {cookies: {token: req.cookies.token}}}
    )

Expected Behaviour

The token should be appended to the header not the body. The docs do not indicate how this is possible, and if they are different, the functionality for GET and POST for the same promise should not be different.

Nathan-Nesbitt avatar Jan 23 '21 22:01 Nathan-Nesbitt

+1, I'm having the same problem

NicTron1 avatar Feb 03 '21 01:02 NicTron1