Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Cambiar el encabezado de la respuesta en NodeJS usando la solicitud

Tengo el siguiente problema:

Quiero obtener un archivo estático de otro servidor y devolvérselo al usuario con otro encabezado de tipo de contenido.

El siguiente código funciona bien, pero no puedo encontrar una manera de cambiar el encabezado de respuesta.

 const request = require('request'); app.get('video', function (req, res) { request.get('http://anotherurl.com/video-sample.mp4').pipe(res); });

Traté de hacer esto de forma más manual, pero la respuesta fue muy lenta.

 app.get('video', function (req, res) { request.get('http://anotherurl.com/video-sample.mp4', function(error, response, body) { // ... res.setHeader('content-type', 'image/png'); res.send(new Buffer(body)); }); });

Pueden ayudarme con eso chicos?

Gracias

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simplemente configure el encabezado de respuesta cuando se active el evento 'response' .

 app.get('video', (req, res) => { request.get('http://anotherurl.com/video-sample.mp4') .on('response', response => { res.setHeader('Content-Type', 'image/png'); // pipe response to res // since response is an http.IncomingMessage response.pipe(res); }); });
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!