██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
Spent the day going through Express middlewares and testing if they work with uExpress. While checking cookie-session
middleware, it didn’t set the header for some reason. After a long debugging, I saw that this code was causing the issue:
It checks for res.set
(which I have implemented) and then uses node’s class setHeader function for some reason. Since I don’t implement that class, I started to think what can I do to fix this.
At first I tried to implement the class, but it caused random issues and almost definitely caused slowdowns, which I really didn’t want. I started thinking of some dumb things like removing res.set
if usage of cookie-session was detected, but it’d be extremely terrible and could cause random bugs. I almost gave up and marked it as incompatible (which I had to do with compression
middleware due to similar random issues), but then I’ve decided to check Node.js’s code and check what that function does:
So it did set the header, but used something called kOutHeaders
as key. I scrolled above and this is what I saw:
Which was:
I don’t have a lot of experience working with Symbols, so I googled and apparently it’s a way to create unique identifier. So I couldn’t just call my headers object kOutHeaders
, I had to actually get out that symbol from there.
At first, the most obvious attempt, I just tried to require it from internals like const { kOutHeaders } = require('internal/http')
, but Node said that internal/http doesn’t exist. Apparently you can’t access internal modules without a flag, so this definitely wouldn’t work as a solution.
Then I went with a second attempt, I got out http.OutgoingMessage
class, created an object from it, and tried to use Object.keys()
on it, which sadly did not show any Symbols, only strings. But to my blessing I found out about Object.getOwnPropertySymbols()
, and it worked. I got out kOutHeaders
from internal module!
After I added this[kOutHeaders] = this.headers;
, it resulted in a bit weird format that Node.js internally uses, so I had to write a proxy that would actually use correct format for my object:
And everything started to work!
All middlewares I use in my servers work fine, yay!
More Yume 2kki at the end of the day. Today’s worlds were definitely more high quality than usual but I still haven’t found something to be really memorable. Visited Secret Society again to appreciate it’s beauty.