Open brunoyang opened 8 years ago
本文分为四个部分,分别对应源码的四个文件。
context暴露了一个对象,包含了多个方法,并将request和response的方法代理到自己身上。
this.app继承自event.emitter,通过error事件触发onerror。onerror方法将取得的error code设置为传入err的status,默认为500,在设置完http相应的长度、状态码及body后,发送该响应至用户。
143~191行,通过delegate方法将response的request的方法绑定至context上。
本文分为四个部分,分别对应源码的四个文件。
依赖
源码分析
context暴露了一个对象,包含了多个方法,并将request和response的方法代理到自己身上。
onerror
this.app继承自event.emitter,通过error事件触发onerror。onerror方法将取得的error code设置为传入err的status,默认为500,在设置完http相应的长度、状态码及body后,发送该响应至用户。
request和response
143~191行,通过delegate方法将response的request的方法绑定至context上。