aruntj / mjpeg-readable-stream

Code to read an Mjpeg stream using the Readable stream api.
MIT License
56 stars 12 forks source link

Problem in getLength function when header is not exactly 'Content-length' #3

Closed martapanc closed 3 years ago

martapanc commented 3 years ago

Hi, I'm using part your code for a personal project, and it works like a charm except for a small issue I found.

Essentially, the mjpeg stream I'm reading from uses a slightly different header for some reason: Content-Length instead of Content-length. No idea how widespread this issue is, but since the solution appears to be very simple I thought to report it to you, so maybe I can save other users some debugging time 😁

My solution was simply to change the CONTENT_LENGTH const to be

const CONTENT_LENGTH = 'content-length';

and then do like

if (pair[0].toLowerCase() === CONTENT_LENGTH) {
    contentLength = pair[1];
}

inside the getLength function, so that it works regardless of the wording. Let me know what you think of it :)

Cheers, Marta

aruntj commented 3 years ago

Thanks for pointing out the issue and providing a fix :) I didn't know this could be a problem. What you suggest seems pretty solid. I'll update the code with your solution since this is too tiny a "project" for a PR :p

martapanc commented 3 years ago

Awesome, glad I was able to help! :)