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.

Set multiple headers at once?

See original GitHub issue

Sorry if this has been addressed - searching came up with nothing. Unless I am missing something, looks like each custom header must be individually using .set(). It would come in very handy to be able set all headers at once as an object or array of objects. Something like this:

const headers = {"Content-Type": "application/json", "Accept": "application/json"};
// OR 
const headers = [{"Content-Type": "application/json"}, {"Accept": "application/json"}];

.setAll(headers)

We have a lot of custom headers and they can be conditional on many things. Now we have to pass a superagent request object to a custom method and have it call .set() on whatever headers it wants to add based on various conditions and dependencies. It’s not the most elegant thing.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

9reactions
jackspanielcommented, May 12, 2017

Hey it looks like this actually works!

.set({"Content-Type":"application/json","Accept":"application/json","Margle":"Bargle"})

Problem solved! Would be good to add to the docs I guess.

1reaction
st0fferncommented, Oct 21, 2019

Very late 😄 i solved it somehow 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set multiple headers data with XMLHttpRequest in ...
If you want to set multiple headers, then call setRequestHeader multiple times. Don't add extra arguments to the first call. Share.
Read more >
Set multiple headers at once? · Issue #1225 · ladjs/superagent
We have a lot of custom headers and they can be conditional on many things. Now we have to pass a superagent request...
Read more >
How to pass more than one header in a request in Rest ...
We can pass more than one header in a request in Rest Assured. A web service can accept headers as parameters while making...
Read more >
How to set header for multiple APIs at once - YouTube
In this video we will discuss.1. How to set header for multiple APIs at a time.ORHow to set Header at collections level.
Read more >
Add multiple headers with conditions to your WordPress site ...
Add as many headers as you like; style them out all individually, and then assign them by display conditions or user conditiosn as...
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