@@ -21,8 +21,9 @@ import (
21
21
)
22
22
23
23
const (
24
- jsonpReqParamKey = "callback"
25
- ajaxHeaderValue = "XMLHttpRequest"
24
+ jsonpReqParamKey = "callback"
25
+ ajaxHeaderValue = "XMLHttpRequest"
26
+ websocketHeaderValue = "websocket"
26
27
)
27
28
28
29
var requestPool = & sync.Pool {New : func () interface {} { return & Request {} }}
@@ -154,12 +155,17 @@ func (r *Request) IsJSONP() bool {
154
155
return ! ess .IsStrEmpty (r .QueryValue (jsonpReqParamKey ))
155
156
}
156
157
157
- // IsAJAX methods returns true if the request header `X-Requested-With` is
158
+ // IsAJAX method returns true if request header `X-Requested-With` is
158
159
// `XMLHttpRequest` otherwise false.
159
160
func (r * Request ) IsAJAX () bool {
160
161
return r .Header .Get (HeaderXRequestedWith ) == ajaxHeaderValue
161
162
}
162
163
164
+ // IsWebSocket method returns true if request is WebSocket otherwise false.
165
+ func (r * Request ) IsWebSocket () bool {
166
+ return r .Header .Get (HeaderUpgrade ) == websocketHeaderValue
167
+ }
168
+
163
169
// PathValue method returns value for given Path param key otherwise empty string.
164
170
// For eg.: /users/:userId => PathValue("userId")
165
171
func (r * Request ) PathValue (key string ) string {
@@ -200,7 +206,8 @@ func (r *Request) Unwrap() *http.Request {
200
206
return r .Raw
201
207
}
202
208
203
- // SaveFile method saves an uploaded multipart file for given key from the HTTP request into given destination
209
+ // SaveFile method saves an uploaded multipart file for given key from the HTTP
210
+ // request into given destination
204
211
func (r * Request ) SaveFile (key , dstFile string ) error {
205
212
if ess .IsStrEmpty (dstFile ) || ess .IsStrEmpty (key ) {
206
213
return errors .New ("ahttp: key or dstFile is empty" )
@@ -219,15 +226,16 @@ func (r *Request) SaveFile(key, dstFile string) error {
219
226
return saveFile (uploadedFile , dstFile )
220
227
}
221
228
222
- // SaveFiles method saves an uploaded multipart file(s) for the given key from the HTTP request into given destination directory.
223
- // It uses the filename as uploaded filename from the request
229
+ // SaveFiles method saves an uploaded multipart file(s) for the given key
230
+ // from the HTTP request into given destination directory. It uses the filename
231
+ // as uploaded filename from the request
224
232
func (r * Request ) SaveFiles (key , dstPath string ) []error {
225
233
if ! ess .IsDir (dstPath ) {
226
234
return []error {fmt .Errorf ("ahttp: destination path, %s is not a directory" , dstPath )}
227
235
}
228
236
229
237
if ess .IsStrEmpty (key ) {
230
- return []error {fmt .Errorf ("ahttp: form file key, %s is empty. " , key )}
238
+ return []error {fmt .Errorf ("ahttp: form file key, %s is empty" , key )}
231
239
}
232
240
233
241
var errs []error
0 commit comments