Skip to content

Commit 111534c

Browse files
committed
godoc update, iswebsocket method added
1 parent 19eeca3 commit 111534c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

request.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
)
2222

2323
const (
24-
jsonpReqParamKey = "callback"
25-
ajaxHeaderValue = "XMLHttpRequest"
24+
jsonpReqParamKey = "callback"
25+
ajaxHeaderValue = "XMLHttpRequest"
26+
websocketHeaderValue = "websocket"
2627
)
2728

2829
var requestPool = &sync.Pool{New: func() interface{} { return &Request{} }}
@@ -154,12 +155,17 @@ func (r *Request) IsJSONP() bool {
154155
return !ess.IsStrEmpty(r.QueryValue(jsonpReqParamKey))
155156
}
156157

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
158159
// `XMLHttpRequest` otherwise false.
159160
func (r *Request) IsAJAX() bool {
160161
return r.Header.Get(HeaderXRequestedWith) == ajaxHeaderValue
161162
}
162163

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+
163169
// PathValue method returns value for given Path param key otherwise empty string.
164170
// For eg.: /users/:userId => PathValue("userId")
165171
func (r *Request) PathValue(key string) string {
@@ -200,7 +206,8 @@ func (r *Request) Unwrap() *http.Request {
200206
return r.Raw
201207
}
202208

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
204211
func (r *Request) SaveFile(key, dstFile string) error {
205212
if ess.IsStrEmpty(dstFile) || ess.IsStrEmpty(key) {
206213
return errors.New("ahttp: key or dstFile is empty")
@@ -219,15 +226,16 @@ func (r *Request) SaveFile(key, dstFile string) error {
219226
return saveFile(uploadedFile, dstFile)
220227
}
221228

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
224232
func (r *Request) SaveFiles(key, dstPath string) []error {
225233
if !ess.IsDir(dstPath) {
226234
return []error{fmt.Errorf("ahttp: destination path, %s is not a directory", dstPath)}
227235
}
228236

229237
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)}
231239
}
232240

233241
var errs []error

0 commit comments

Comments
 (0)