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.

feat: set headers in individual query and be able to write Buffer data for attachment download

See original GitHub issue

Describe the feature you’d like to request

Make the response a download request so browser can immediate initiate the download right away

e.g.

      //res.header('Content-Disposition', `attachment; filename="${fileName}"`)
      //res.header('Content-Type', fileType)

      //const download = Buffer.from(fileData); // fileData is a string
      //res.end(download)

Describe the solution you’d like to see

able to use res.header() right now res.header() will throw an error that the request has already been sent

same thing with res.end(), where right now it will throw circular json when it is simply a string

Desribe alternate solutions

I don’t know any viable ones, ideally the ones shown above in the solution makes the most sense and the most striaghtforward

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I’d be down to file a PR implementing this feature!

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pencilcheckcommented, Nov 14, 2022

I tested with various entry points with various results but one thing for sure, that setHeader didn’t throw any error anymore, very encouraging.

Trying to add custom header “TEST”: “test”

Tested on postman Result: it showed up in the response header field, hooray!!

Tested from browser calling the method using @trpc/client Result: no error but the header didn’t show up in the response header field when viewing from inspector, :\

Screenshot 2022-11-14 at 1 37 25 PM

It is very likely due to CORS, will need to check again

------------- update -------------

Weird, after CORS allowing all headers, the custom headers still didn’t show up.

Screenshot 2022-11-14 at 1 42 43 PM

Also, changing the CORS header somehow made postman not working anymore (request still succeeded but the custom header isn’t set), not sure why

------------- update -------------

sorry for the back and forth but I restarted the server a couple of times and suddenly the header shows up in the browser method now!!

I guess it works just sometimes it is unstable?? But it works now.

I appreciated the help, I guess header and writeHead both sends the requests implicitly?? I really don’t know the implementation details on but setHeader seems to work as expected.

Thanks again.

Look forward to the feature for content-type being available, that would be awesome.

Since I have gotten the feature I will close this one.

0reactions
KATTcommented, Nov 14, 2022

Thanks for sharing your process! ♥

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set a header for a HTTP GET request, and trigger file ...
There are two ways to download a file where the HTTP request requires that a header be set. The credit for the first...
Read more >
umijs/umi-request: A request tool based on fetch. - GitHub
toLowerCase() === 'get' }, // 'requestType' umi-request will add headers and body according to the 'requestType' when the type of data is object...
Read more >
HTTPie 3.2.1 (latest) docs
Each request item is simply a key/value pair separated with the following characters: : (headers), = (data field, e.g., JSON, form), := (raw...
Read more >
Assistance with Importing CSV with headers on row 2
We have an integration from peoplesoft where data was emailed in with attachment, in xlsx format, that had the headers on row 2,...
Read more >
HAProxy version 2.2.22 - Configuration Manual - GitHub Pages
In order to make this possible, HAProxy supports character escaping by ... Sets the path of the DeviceAtlas JSON data file to be...
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