forked from Rob--W/cors-anywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
112 lines (93 loc) · 2.46 KB
/
setup.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var nock = require('nock');
nock.enableNetConnect('127.0.0.1');
function echoheaders(origin) {
nock(origin)
.persist()
.get('/echoheaders')
.reply(function() {
var headers = this.req.headers;
var excluded_headers = [
'accept-encoding',
'user-agent',
'connection',
// Remove this header since its value is platform-specific.
'x-forwarded-for',
'test-include-xfwd',
];
if (!('test-include-xfwd' in headers)) {
excluded_headers.push('x-forwarded-port');
excluded_headers.push('x-forwarded-proto');
}
var response = {};
Object.keys(headers).forEach(function(name) {
if (excluded_headers.indexOf(name) === -1) {
response[name] = headers[name];
}
});
return response;
});
}
nock('http://example.com')
.persist()
.get('/')
.reply(200, 'Response from example.com')
.post('/echopost')
.reply(200, function(uri, requestBody) {
return requestBody;
})
.get('/setcookie')
.reply(200, '', {
'Set-Cookie': 'x',
'Set-Cookie2': 'y',
'Set-Cookie3': 'z', // This is not a special cookie setting header.
})
.get('/redirecttarget')
.reply(200, 'redirect target', {
'Some-header': 'value',
})
.head('/redirect')
.reply(302, '', {
Location: '/redirecttarget',
})
.get('/redirect')
.reply(302, 'redirecting...', {
'header at redirect': 'should not be here',
Location: '/redirecttarget',
})
.get('/redirectposttarget')
.reply(200, 'post target')
.post('/redirectposttarget')
.reply(200, 'post target (POST)')
.post('/redirectpost')
.reply(302, 'redirecting...', {
Location: '/redirectposttarget',
})
.post('/redirect307')
.reply(307, 'redirecting...', {
Location: '/redirectposttarget',
})
.get('/redirect2redirect')
.reply(302, 'redirecting to redirect...', {
Location: '/redirect',
})
.get('/redirectloop')
.reply(302, 'redirecting ad infinitum...', {
Location: '/redirectloop',
})
.get('/redirectwithoutlocation')
.reply(302, 'maybe found')
.get('/proxyerror')
.replyWithError('throw node')
;
nock('https://example.com')
.persist()
.get('/')
.reply(200, 'Response from https://example.com')
;
echoheaders('http://example.com');
echoheaders('http://example.com:1337');
echoheaders('https://example.com');
echoheaders('https://example.com:1337');
nock('http://robots.txt')
.get('/')
.reply(200, 'this is http://robots.txt');