Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
How to set headers of stream response so I can infer then on next stream.on("data", ()=>{}) handler in Node.js?

Background: I am trying to be able to make some unique identifier for each client that connects and stream to my service such that whenever they make a new request I can detect and block them from restreaming from my site until they stop the current stream.

DISCLAIMER: I am new to streaming, I was hoping that maybe on the New request object somewhere I would be able to tall if a user is streaming. I think somehow this is can be for socket application

Bellow is my code so far. The idea is to somehow be able to tell how many stream each client(Broswer) is streaming on each time they send request to my server.

app.get('/video', function (req, res) {

  const path = 'abc.mp4'
  const stat = fs.statSync(path)
  const fileSize = stat.size
  const range = req.headers.range

  if (range) {
    // console.log("Has range: ", range)
    const parts = range.replace(/bytes=/, "").split("-")
    const start = parseInt(parts[0], 10)
    const end = parts[1]
      ? parseInt(parts[1], 10)
      : fileSize - 1

    const chunksize = (end - start) + 1
    const file = fs.createReadStream(path, { start, end })

    const head = {
      'Content-Range': `bytes ${start}-${end}/${fileSize}`,
      'Accept-Ranges': 'bytes',
      'Content-Length': chunksize,
      'Content-Type': 'video/mp4',
      'MY_UNIQUE_ID': "Hello World" + new Date().toISOString()
    }



    res.writeHead(206, head)

    file.pipe(res)

    file.on("data", function (chunk) {
      if (!!req.headers) {
        //Expecting to also have MY_UNIQUE_ID
        console.log(req.headers)
      }
    });

  }
})
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda