Is it possible to remove the User-agent header in a supertest?

I am trying to write some Supertests where the User-Agent header is sent with a value, empty or not at all.

I know I can use .set to handle the value for that header, or '' for empty, but I'm not sure how to omit the User-agent header entirely. If I leave that alone, the supertest request will send the default node -superagent / 1.2.0. If I.set ('User-agent', null), it sends 'null' over the wire.

There seems to be no .remove or .delete. Anyone have an idea?

it ('example', function(done){
  agent.post('/abc/a')
  .set('User-agent', 'some agent')
  .send('abc')
  .expect(200)
  .end(function(err, results){})
};
      

Run code


+3


source to share


1 answer


The method is called .unset()

. You can use the following:



it ('example', function(done){
  agent.post('/abc/a')
  .unset('User-Agent')
  .send('abc')
  .expect(200)
  .end(function(err, results){})
};

      

+4


source







All Articles