question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I set the User-Agent header using the node module?

See original GitHub issue

Im trying to test that my system idenfifies user-agents correctly

using mocha, in my test code, before function - I have:

        before(function(done) { 
              //...some actions
              //...some actions
               superagent.post('http://localhost:8080/api/v1/path1')
                    .send(body)
                    .set('Referrer', 'http://dummy.domain.com/somepage.html')
                    .set('User-Agent', "some spoofed agent")
                    .end(function (e, r) {
                        res = r;
                        _done();
                    });
       })

however,the server gets

'node-superagent/1.3.0'

Help?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
ixtlicommented, Jul 19, 2016

I’m also having this issue when doing

            request
                .get(url)
                .set('User-Agent', uaString)
                .end((err, resp) => {
                    console.log(resp.body);
                    done();
                });

with node 6.2.1.

I think it’s clear that OP was not trying to override this request from a browser, otherwise it would not have identified itself as node-superagent/1.3.0.

EDIT: I can also confirm that the object that is being returned by .end() has a top level key called _headers which does contain ‘user-agent’ (lowercase) with a value of uaString.

1reaction
timsar2commented, Jul 27, 2019

npm install ionic@latest … GitHub blocks requests without a User-Agent header

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - How to set user-agent in nodejs? - Stack Overflow
The docs for the HTTP module nodejs.org/api/http.html#http_http_request_options_callback show that agent is something different. The user-agent ...
Read more >
How can I set the User-Agent header using the node module?
Im trying to test that my system idenfifies user-agents correctly using mocha, in my test code, before function - I have: ...
Read more >
Handling User-Agents in Node.js - GeeksforGeeks
Setting up of User-Agent Module: To enable this module, first you need to initialize the application with package.json file and then install ......
Read more >
How to set User-Agent header with Puppeteer JS and not fail
How to set User-Agent header with Puppeteer JS and not fail ... We setup Puppeteer JS, open the browser, load webpage and get...
Read more >
express-useragent - npm
express-useragent is a simple NodeJS/ExpressJS user-agent middleware exposing user-agent details to your application and views. Installation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found