0

¿Cómo modificar la cabecera de una petición en Node.js antes de enviarla?

 res.set({
  'Content-Type': 'text/plain',
  'Content-Length': '123',
  'ETag': '1234532323232323232323'
});
res.redirect(sitionweb);

Probé con eso pero cuando miro la petición con console.log(req) no aparece las modificaciones que hice.

2 respuestas 2

0

¿Esto es lo que buscàs?

res.writeHead(statusCode, {header: value, header: value});

Por ejemplo:

res.writeHead(200, {
   'content-type': 'text/html'
};
0

Modificas tu Header con el contenido de un html externo de la siguiente manera:

Index.js

var fs=require('fs');
var http=require('http');
http.createServer(function(request,response)
{
    response.writeHead(200,{"Content-Type":"text/html"});
    fs.readFile(__dirname + '/leer_html.html',function(error,content){
        response.write(content);
         response.end();
    });
}).listen(6969,function(){
console.log("Servidor Corriendo.... Puerto 6969");
});

y tu archivo leer_html.html

    <!DOCTYPE html>
    <html lang="es">
    <head>
    <meta charset="utf-8">
    <title>Node Js</title>
    </head>
    <body>
    <h1>Bienvenido Humano</h1>
    </body>
    </html>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.