@@ -58,36 +58,81 @@ module.exports.parseQuery = function parseQuery(query, engine, kwargs) {
58
58
module . exports . parseRequest = function parseRequest ( req , kwargs ) {
59
59
kwargs = kwargs || { } ;
60
60
61
- // headers
61
+ // headers:
62
+ //
63
+ // node: req.headers
64
+ // express: req.header
65
+ // koa: req.header
66
+ //
62
67
var headers = req . header || req . headers || { } ;
63
68
64
- // method
69
+ // method:
70
+ //
71
+ // node: req.method
72
+ // express: req.method
73
+ // koa: req.method
74
+ //
65
75
var method = req . method ;
66
76
67
- // host
77
+ // host:
78
+ //
79
+ // node: req.headers.host
80
+ // express: req.host
81
+ // koa: req.host
82
+ //
68
83
var host = req . host || headers . host || '<no host>' ;
69
84
70
- // protocol
85
+ // protocol:
86
+ //
87
+ // node: <n/a>
88
+ // express: req.protocol
89
+ // koa: req.protocol
90
+ //
71
91
var protocol = ( 'https' === req . protocol || true === req . secure || true === ( req . socket || { } ) . encrypted ||
72
92
( 'https' === ( headers [ 'x-forwarded-proto' ] || '' ) . split ( / \s * , \s * / ) [ 0 ] ) ) ||
73
- ( 443 === Number ( headers [ 'x-forwarded-port' ] || '' ) ) ? 'https' : 'http' ;
93
+ ( ' 443' === headers [ 'x-forwarded-port' ] || '' ) ? 'https' : 'http' ;
74
94
75
- // url (including path and query string)
76
- var originalUrl = req . url ;
95
+ // url (including path and query string):
96
+ //
97
+ // node: req.originalUrl
98
+ // express: req.originalUrl
99
+ // koa: req.url
100
+ //
101
+ var originalUrl = req . originalUrl || req . url ;
77
102
78
103
// absolute url
79
104
var url = protocol + '://' + host + originalUrl ;
80
105
81
106
// query string
107
+ //
108
+ // node: req.url (raw)
109
+ // express: req.query
110
+ // koa: req.query
111
+ //
82
112
var query = req . query || urlParser . parse ( originalUrl || '' , true ) . query ;
83
113
84
- // cookies
114
+ // cookies:
115
+ //
116
+ // node: req.headers.cookie
117
+ // express: req.cookies (expressjs/cookies)
118
+ // koa: req.headers.cookie
119
+ //
85
120
var cookies = ( isPlainObject ( req . cookies ) ? req . cookies : '' ) || cookie . parse ( headers . cookie || headers . cookies || '' ) ;
86
121
87
- // body data
122
+ // body data:
123
+ //
124
+ // node: req.body
125
+ // express: req.body
126
+ // koa: req.body
127
+ //
88
128
var data = req . body || '<unavailable>' ;
89
129
90
- // client ip
130
+ // client ip:
131
+ //
132
+ // node: req.connection.remoteAddress
133
+ // express: req.ip
134
+ // koa: req.ip
135
+ //
91
136
var ip = req . ip || ( headers [ 'x-forwarded-for' ] || '' ) . split ( / \s * , \s * / ) [ 0 ] || ( req . connection || { } ) . remoteAddress ;
92
137
93
138
// http interface
0 commit comments