superdeno icon indicating copy to clipboard operation
superdeno copied to clipboard

`HandlerLike` signature doesn't match actual `server.Handler`. Missing `connInfo`

Open ericls opened this issue 3 years ago • 4 comments

HandlerLike signature doesn't match actual server.Handler. Missing connInfo

Setup:

  • Deno Version: deno 1.20.6
  • v8 Version: v8 10.0.139.6
  • Typescript Version: 4.6.2
  • SuperDeno Version: 4.8

Details

The actual server.Handler takes a second argument called connInfo that contains information for the http request. See here and quoted:

export type Handler = (
  request: Request,
  connInfo: ConnInfo,
) => Response | Promise<Response>;

But RequestHandlerLike defined in this project doesn't match that. And when actually testing the handler, this project calls the handler with return await app(request); with the connInfo argument missing.

ericls avatar Jun 01 '22 03:06 ericls

Yeah good point - guessing noticed this because you rely on connInfo in a handler using the std lib http server?

Alongside supporting std lib, we also want to support the likes of oak etc., e.g. see https://github.com/oakserver/oak#handle-method.

The second conn arg for Oak is a superset of connInfo I implemented for the std lib so suspect can just passing the full conn and that should work for most / all use-cases. Will just need some loose typing, e.g.

interface ConnLike extends ConnInfo {}

asos-craigmorten avatar Jun 01 '22 09:06 asos-craigmorten

@asos-craigmorten , yea that sounds reasonable. I haven't looked into the other frameworks/tools this library tries to support tho.. And when testing I guess it can just pass in a fake ConnLike or make a method to allow the user to specify it? Something like:

superdeno(...)
  .setConn()

?

ericls avatar Jun 02 '22 03:06 ericls

@asos-craigmorten , yea that sounds reasonable. I haven't looked into the other frameworks/tools this library tries to support tho.. And when testing I guess it can just pass in a fake ConnLike or make a method to allow the user to specify it? Something like:

superdeno(...)
  .setConn()

?

Okay, I took a look at the code and find my previous statement doesn't make much sense and the connection info is not easy to mock in this case. Looks like we just need to fix the typing and actually pass the connInfo to the handler function in the managed server instance.

ericls avatar Jun 04 '22 01:06 ericls

Going to reopen as think this is valid, and be good to keep to track the fix/feature (depending on how see it!)

asos-craigmorten avatar Jun 06 '22 08:06 asos-craigmorten

I'm rewriting tinyhttp for native http and I faced a similar problem. The app.handle needs both req and connInfo

v1rtl avatar Mar 25 '23 14:03 v1rtl