@@ -23,7 +23,7 @@ const (
23
23
type (
24
24
// Request is extends `http.Request` for aah framework
25
25
Request struct {
26
- // Schema value is protocol info ; it's a derived value in the order as below.
26
+ // Scheme value is protocol; it's a derived value in the order as below.
27
27
// - `X-Forwarded-Proto` is not empty return value as is
28
28
// - `http.Request.TLS` is not nil value is `https`
29
29
// - `http.Request.TLS` is nil value is `http`
@@ -41,24 +41,26 @@ type (
41
41
// Header request HTTP headers
42
42
Header http.Header
43
43
44
- // Payload holds the value from HTTP request for `Content-Type`
45
- // JSON and XML.
46
- Payload []byte
47
-
48
- // ContentType the parsed HTTP header `Content-Type`.
44
+ // ContentType the parsed value of HTTP header `Content-Type`.
45
+ // Partial implementation as per RFC1521.
49
46
ContentType * ContentType
50
47
51
48
// AcceptContentType negotiated value from HTTP Header `Accept`.
52
49
// The resolve order is-
53
50
// 1) URL extension
54
- // 2) Accept header.
51
+ // 2) Accept header (As per RFC7231 and vendor type as per RFC4288)
55
52
// Most quailfied one based on quality factor otherwise default is HTML.
56
53
AcceptContentType * ContentType
57
54
58
55
// AcceptEncoding negotiated value from HTTP Header the `Accept-Encoding`
56
+ // As per RFC7231.
59
57
// Most quailfied one based on quality factor.
60
58
AcceptEncoding * AcceptSpec
61
59
60
+ // Payload holds the value from HTTP request for `Content-Type`
61
+ // JSON and XML.
62
+ Payload []byte
63
+
62
64
// Params contains values from Path, Query, Form and File.
63
65
Params * Params
64
66
@@ -68,10 +70,12 @@ type (
68
70
// UserAgent value of the HTTP 'User-Agent' header.
69
71
UserAgent string
70
72
71
- // ClientIP remote client IP address.
73
+ // ClientIP remote client IP address aka Remote IP. Parsed in the order of
74
+ // `X-Forwarded-For`, `X-Real-IP` and finally `http.Request.RemoteAddr`.
72
75
ClientIP string
73
76
74
77
// Locale negotiated value from HTTP Header `Accept-Language`.
78
+ // As per RFC7231.
75
79
Locale * Locale
76
80
77
81
// IsGzipAccepted is true if the HTTP client accepts Gzip response,
@@ -131,7 +135,8 @@ func (r *Request) Cookies() []*http.Cookie {
131
135
return r .Raw .Cookies ()
132
136
}
133
137
134
- // IsJSONP method returns true if request query string has "callback=function_name".
138
+ // IsJSONP method returns true if request URL query string has "callback=function_name".
139
+ // otherwise false.
135
140
func (r * Request ) IsJSONP () bool {
136
141
return ! ess .IsStrEmpty (r .QueryValue (jsonpReqParamKey ))
137
142
}
@@ -142,29 +147,31 @@ func (r *Request) IsAJAX() bool {
142
147
return r .Header .Get (HeaderXRequestedWith ) == ajaxHeaderValue
143
148
}
144
149
145
- // PathValue method return value for given Path param key otherwise empty string.
150
+ // PathValue method returns value for given Path param key otherwise empty string.
151
+ // For eg.: /users/:userId => PathValue("userId")
146
152
func (r * Request ) PathValue (key string ) string {
147
153
return r .Params .PathValue (key )
148
154
}
149
155
150
- // QueryValue method return value for given query (aka URL) param key
156
+ // QueryValue method returns value for given URL query param key
151
157
// otherwise empty string.
152
158
func (r * Request ) QueryValue (key string ) string {
153
159
return r .Params .QueryValue (key )
154
160
}
155
161
156
- // QueryArrayValue method return array value for given query (aka URL)
157
- // param key otherwise empty string.
162
+ // QueryArrayValue method returns array value for given URL query param key
163
+ // otherwise empty string slice .
158
164
func (r * Request ) QueryArrayValue (key string ) []string {
159
165
return r .Params .QueryArrayValue (key )
160
166
}
161
167
162
- // FormValue methos returns value for given form key otherwise empty string.
168
+ // FormValue method returns value for given form key otherwise empty string.
163
169
func (r * Request ) FormValue (key string ) string {
164
170
return r .Params .FormValue (key )
165
171
}
166
172
167
- // FormArrayValue methos returns value for given form key otherwise empty string.
173
+ // FormArrayValue method returns array value for given form key
174
+ // otherwise empty string slice.
168
175
func (r * Request ) FormArrayValue (key string ) []string {
169
176
return r .Params .FormArrayValue (key )
170
177
}
@@ -182,10 +189,10 @@ func (r *Request) Reset() {
182
189
r .Method = ""
183
190
r .Path = ""
184
191
r .Header = nil
185
- r .Payload = nil
186
192
r .ContentType = nil
187
193
r .AcceptContentType = nil
188
194
r .AcceptEncoding = nil
195
+ r .Payload = nil
189
196
r .Params = nil
190
197
r .Referer = ""
191
198
r .UserAgent = ""
@@ -199,7 +206,8 @@ func (r *Request) Reset() {
199
206
// Params methods
200
207
//___________________________________
201
208
202
- // PathValue method return value for given Path param key otherwise empty string.
209
+ // PathValue method returns value for given Path param key otherwise empty string.
210
+ // For eg.: `/users/:userId` => `PathValue("userId")`.
203
211
func (p * Params ) PathValue (key string ) string {
204
212
if p .Path != nil {
205
213
if value , found := p .Path [key ]; found {
@@ -209,30 +217,31 @@ func (p *Params) PathValue(key string) string {
209
217
return ""
210
218
}
211
219
212
- // QueryValue method return value for given query (aka URL) param key
220
+ // QueryValue method returns value for given URL query param key
213
221
// otherwise empty string.
214
222
func (p * Params ) QueryValue (key string ) string {
215
223
return p .Query .Get (key )
216
224
}
217
225
218
- // QueryArrayValue method return array value for given query (aka URL)
219
- // param key otherwise empty string.
226
+ // QueryArrayValue method returns array value for given URL query param key
227
+ // otherwise empty string slice .
220
228
func (p * Params ) QueryArrayValue (key string ) []string {
221
229
if values , found := p .Query [key ]; found {
222
230
return values
223
231
}
224
232
return []string {}
225
233
}
226
234
227
- // FormValue methos returns value for given form key otherwise empty string.
235
+ // FormValue method returns value for given form key otherwise empty string.
228
236
func (p * Params ) FormValue (key string ) string {
229
237
if p .Form != nil {
230
238
return p .Form .Get (key )
231
239
}
232
240
return ""
233
241
}
234
242
235
- // FormArrayValue methos returns value for given form key otherwise empty string.
243
+ // FormArrayValue method returns array value for given form key
244
+ // otherwise empty string slice.
236
245
func (p * Params ) FormArrayValue (key string ) []string {
237
246
if p .Form != nil {
238
247
if values , found := p .Form [key ]; found {
@@ -242,8 +251,8 @@ func (p *Params) FormArrayValue(key string) []string {
242
251
return []string {}
243
252
}
244
253
245
- // FormFile method returns the first file for the provided form key otherwise
246
- // returns error. It is caller responsibility to close the file.
254
+ // FormFile method returns the first file for the provided form key
255
+ // otherwise returns error. It is caller responsibility to close the file.
247
256
func (p * Params ) FormFile (key string ) (multipart.File , * multipart.FileHeader , error ) {
248
257
if p .File != nil {
249
258
if fh := p .File [key ]; len (fh ) > 0 {
0 commit comments