forked from nightwatchjs/nightwatch
/
http.js
49 lines (43 loc) · 1019 Bytes
/
http.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const ContentTypes = {
JSON: 'application/json',
JSON_WITH_CHARSET: 'application/json; charset=utf-8',
MULTIPART_FORM_DATA: 'multipart/form-data'
};
const Headers = {
ACCEPT: 'accept',
CONTENT_TYPE: 'content-type',
CONTENT_LENGTH: 'content-length',
AUTHORIZATION: 'authorization'
};
const Http = module.exports = {
Method: {
POST: 'POST',
PUT: 'PUT',
DELETE: 'DELETE',
GET: 'GET'
},
StatusCode: {
MOVED_PERMANENTLY: 301,
MOVED_TEMPORARILY: 302,
SEE_OTHER: 303,
NOT_MODIFIED: 304,
TEMPORARY_REDIRECT: 307
},
isRedirect(statusCode) {
return [
Http.StatusCode.MOVED_PERMANENTLY,
Http.StatusCode.MOVED_TEMPORARILY,
Http.StatusCode.SEE_OTHER,
Http.StatusCode.NOT_MODIFIED
].indexOf(statusCode) > -1;
},
needsContentLengthHeader(requestMethod) {
return [
Http.Method.POST,
Http.Method.PUT,
Http.Method.DELETE
].indexOf(requestMethod) > -1;
},
Headers: Headers,
ContentTypes: ContentTypes
};