dongyuanxin / blog

📚 专注Web与算法
https://0x98k.com
MIT License
1.37k stars 184 forks source link

「评论」koa源码:架构设计 #133

Open dongyuanxin opened 5 years ago

dongyuanxin commented 5 years ago

koa源码:架构设计:https://xin-tan.com/passages/2019-06-18-deep-in-koa/

theniceangel commented 5 years ago

ctx.headers 访问的是 ctx.reqeust 上的 headers

这一处有笔误。应该是 ctx.request。

ctx.headers 代理 ctx.res.headers

感觉这一块说的不是很清晰。按照逻辑的流向应该是 ctx.headers 求值是先执行 ctx.request.headers,而 ctx.request.headers 的求值是执行 this.req.headers,当前的 this 指向的是 request,最后也就是 request.req.headers,request.req 就是请求的 request,这样就拿到浏览器传过来的 headers 了。

dongyuanxin commented 5 years ago

@theniceangel

Thanks♪(・ω・)ノ,笔误已修改,关于 ctx.headers 那部分也重新写了下。文中实名感谢老哥,哈哈

theniceangel commented 5 years ago

@dongyuanxin 之前就一直关注你了,感觉你还是特别能折腾,算是志同道合吧,要是你在北京,可以内推你到我们组😊

theniceangel commented 5 years ago

还有就是觉得 koa 的源码你可以写的再详细点,比如 koa-compose 为啥要这么实现,可以画图解释下洋葱模型。

dongyuanxin commented 5 years ago

@theniceangel 还有就是觉得 koa 的源码你可以写的再详细点,比如 koa-compose 为啥要这么实现,可以画图解释下洋葱模型。

洋葱模型网上有好多,就没有再画图了。有时候顺着思路就写下去了,就没有那么细致