Following the theme of this week, another repo I stumbled upon this week was tinyhttp, which is another web framework.
However, unlike AdonisJS (a "full featured" framework), tinyhttp aims for speed and simplicity by trying to minimize all of its dependencies.
I worked on Issue 360. Essentially, when a user would set the "Content-Type" header before returning the file, the framework would overwrite the "previous" header, with the type that it determined from the files type.
To solve this issue, I first spent time reading the "Response" and looking at the code for res.sendFile().
I saw that on line 73, there was no check in place to see if the "Content-Type" header had previously been written.
After this, I got curious on how Express handles this situation. What I found is that in Express, res.sendFile() will not actually set the "Content-Type" header, but instead it gets deferred to a separate function, and use the Node function "res.setHeader()", to handle it. This will actually result in the header being over written (just like tinyhttp).
I checked AdonisJS, and the header will also get overwritten useing that framework too. This makes me think that this is a very niche use-case, but because the maintainer was looking for a PR, I added a check to only change the "Content-Type" header if it has not been previously set. I am curious to hear the maintainer's comments.
My PR can be found here: https://github.com/tinyhttp/tinyhttp/pull/363
Top comments (0)