cookie in redirected response - node.js

As shown in the image below, I am trying to get the set-cookie in the first redirect#1 response.
I succeed to get the response with request module by setting followRedirect to be false in the request options, but I still could not get the set-cookie from the header.
A similar discussion here: https://github.com/request/request/issues/1502
Anyone has managed to use any other module to get the cookie from redirected response? Thanks a lot in advance!

response.headers['set-cookie'] should return the values you want.

Related

how to modify response status code in chrome extension?

using chrome.webRequest I can modify request or response headers, however I also need modify Response.statusCode, is it possible? I do not see anything in documentation.
https://developer.chrome.com/docs/extensions/reference/webRequest/
I see something interesting here:
https://tweak-extension.com/blog/how-to-override-http-status-code#lets-override
It seems the request is not sent but a mock response has been applied but I'm not sure how.

How does Access-Control-Expose-Headers work?

I understand it determines the headers the client can access from the server response, however, I am confused on exactly when this is applied. Does it determine the headers for every cross-origin request that is allowed by the Access-Control-Allow-Origin header?
To test this I setup a test site in express and put the following code in it:
app.get('/',(req,res)=>{
res.set('Access-Control-Allow-Origin','https://www.google.com') // to be able to make a cross-origin request
res.set('foo', 'bar') //custom header that should get filtered because i havent set the access-control-expose-headers header
res.send('Hello world')
})
Based on my understanding of this, because I haven't set any special Access-Control-Expose-Headers header in the response, the client should only be able to access CORS-safelisted response headers and therefore should not be able to see my foo header.
But when I'm at https://www.google.com (Which I allowed for CORS with the Access-Control-Allow-Origin header) and send a GET request to my test site I see the foo header in the response just fine. Why is this? Could someone explain how this works or at least point me in the right direction? Thanks in advance.
I figured it out. The reason I was receiving my custom header was that I was reading the response headers in the Network tab of Chrome Dev Tools. When I run this script:
fetch('http://127.0.0.1:3000/')
.then(r => {console.log(response.headers.get('foo'))})
It prints null. So the header is not actually accessible to the fetch request, only to the Dev Tools.

Getting Unsafe URL error when trying to send POST request from Firefox console

When I try to send a POST request, I am getting Unsafe URL error. How can I solve this problem? What could be the problem?
This is not an error. This is the value the server sets for the Referrer-Policy header.
You can change it via response.setHeader('Referrer-Policy', 'same-origin') to e.g. same-origin or remove it via response.removeHeader('Referrer-Policy').

Node Express parses request body with JSON incorrectly

I am sending a JSON object from web client, which looks like this:
{"AudioEncoder":{"Settings":{"1":{"audio_bitrate":"16000"}}}}
And in the request I get from req.body.myvalue:
{"AudioEncoder":{"Settings":[null,{"audio_bitrate":"16000"}]}}
In the Network panel of my browser I see correct value though:
myvalue[AudioEncoder][Settings][1][audio_bitrate]:16000
Error is where I am expecting object with key {1:... but get [null:....
Any ideas why would this happen?
I suspect your browser isn't actually sending JSON, it's sending application/x-www-form-urlencoded. This is not the correct value if you are trying to have the browser send JSON: myvalue[AudioEncoder][Settings][1][audio_bitrate]:16000. That's not JSON. Check the request headers for Content-Type and look at the raw body of the request to verify this. If you post your browser JS that's sending the AJAX, we can help you fix that. jQuery makes it a little tricky to specify the options correctly to get it to really send JSON.

Response Cookie not getting set in Kohana

I'm trying to pull out the value of a cookie from the response of an external request in Kohana 3.2
$response = Request::factory('http://myurl')->execute();
echo $response->cookie('cookie');
Now in my example above, the server response from 'http://myurl' is setting the cookie cookie. In fact, if I do print_r($response->headers()); I can see the cookie being set in the set-cookie header.
But yet when I just try to access the cookie from $response->cookie('cookie'); I don't get anything.
Is there something I'm doing wrong?
I had exactly the same problem - I solved it using $response->headers('Cookie')

Resources