You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Socket}from'net';consttrustRemoteAddress=({ remoteAddress}: Pick<Socket,'remoteAddress'>)=>{// Or might be picked from IncomingMessage as well, so it'll be `req.socket.remoteAddress`constval=connection.remoteAddress
I haven't found the solution for the second one, and I don't have the time to work on this yet. So if anyone's up for this, they're absolutely welcome.
I tried working on the second one and found this https://nodejs.org/api/tls.html#tls_tlssocket_encrypted but the req.socket here is a normal net.Socket instance so I could'nt figure out how to use the tlsSocket.encrypted function
import{TLSSocket}from'tls'exportinterfaceRequestextendsIncomingMessage{originalUrl: stringpath: stringurl: stringquery: ParsedUrlQueryparams: URLParamsconnection: Connectionsocket: TLSSocket|Socket// I added this
...
}consttrustRemoteAddress=({ socket }: Pick<IncomingMessage,'socket'>)=>{constval=socket.remoteAddressif(typeofval==='function')returnvalif(typeofval==='boolean'&&val===true)return()=>trueif(typeofval==='number')return(_: unknown,i: number)=>(val ? i<val : undefined)if(typeofval==='string')returncompile(val.split(',').map((x)=>x.trim()))returncompile(val||[])}exportconstgetProtocol=(req: Request): Protocol=>{constproto=req.socketinstanceofTLSSocket&&req.socket.encrypted ? 'https' : 'http'if(!trustRemoteAddress(req))returnprotoconstheader=(req.headers['X-Forwarded-Proto']asstring)||protoconstindex=header.indexOf(',')returnindex!==-1 ? header.substring(0,index).trim() : header.trim()}// Lines 60 and 63 are also to be changed the same way
Activity
[-]Deprecation notice for the usage of `req.connection`[/-][+]Replace `req.connection` with `req.socket`[/+]diivi commentedon Oct 1, 2021
I tried working on the second one and found this https://nodejs.org/api/tls.html#tls_tlssocket_encrypted but the req.socket here is a normal net.Socket instance so I could'nt figure out how to use the tlsSocket.encrypted function
younes-io commentedon Oct 8, 2021
This is my proposal :
What do you think?
v1rtl commentedon Oct 23, 2021
@younes-io does it pass tinyhttp tests?
younes-io commentedon Oct 23, 2021
@talentlessguy when I pull the repo, and run the tests I get this:

After my updates, I run the tests again, and I get exactly the same results.
Is the contributing section up-to-date?
v1rtl commentedon Oct 23, 2021
@younes-io try running
pnpm i && pnpm build -ryounes-io commentedon Oct 23, 2021
@talentlessguy I get exactly the same outcome. I also tried
pnpm prerelease, but in vain. By the way, I tried with node14.18.0and16.6.2v1rtl commentedon Oct 23, 2021
@younes-io delete and clone the repo again, check twice if branch is master, then try the same
younes-io commentedon Oct 23, 2021
@talentlessguy Indeed, it worked after deleting and re-pulling the repo. Thank you!
I created a PR #328