You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/node
const request = require("sync-request");
function getDataFromUrl(src) {
const res = request("GET", src, {
headers: {
"User-Agent": "sync-request/6.1.0"
}});
return res.getBody("utf8");
};
result = getDataFromUrl(process.argv.slice(2)[0]);
console.log(result);
It simply does a request to the url passed via command line argument setting the header User-Agent to sync-request/6.1.0 and prints the result.
If i run it to check the header it sends to the URL https://headers.cloxy.net/request.php everything looks ok. But when I try the URL http://headers.cloxy.net/request.php (without https) it doesn't work as expected. This is because the url with http does a re-direct to the url with https and then sync-request doesn't set the user-agent header on the final url when following the redirection from the original url.
Consider the following test program
It simply does a request to the url passed via command line argument setting the header
User-Agent
tosync-request/6.1.0
and prints the result.If i run it to check the header it sends to the URL https://headers.cloxy.net/request.php everything looks ok. But when I try the URL http://headers.cloxy.net/request.php (without https) it doesn't work as expected. This is because the url with
http
does a re-direct to the url withhttps
and then sync-request doesn't set the user-agent header on the final url when following the redirection from the original url.Example:
Note how in this second request, following the redirect, it not only dropped the
User-Agent
header but also TheAccept-Encoding
oneThe url at the
http
site does a standard301
redirect to the site withhttps
as shown belowThe text was updated successfully, but these errors were encountered: