diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 14:09:23 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 14:09:23 +0100 |
commit | b718fd22374d64534bcfe69932cf562894abed6a (patch) | |
tree | 311d3c67e2a4d1f33ebdd1dc163527de9d33d0f7 /shared/utils/requests | |
parent | adb115f5522bea4d52456a9fc5eb4140bb064476 (diff) | |
parent | 501e961199578129629cf0567033d13efced9904 (diff) | |
download | PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.tar.gz PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.tar.zst PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.zip |
Merge branch 'develop' into pr/1285
Diffstat (limited to 'shared/utils/requests')
-rw-r--r-- | shared/utils/requests/requests.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/shared/utils/requests/requests.ts b/shared/utils/requests/requests.ts index 77e9f6164..6b59e24fc 100644 --- a/shared/utils/requests/requests.ts +++ b/shared/utils/requests/requests.ts | |||
@@ -1,24 +1,32 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { buildAbsoluteFixturePath, root } from '../miscs/miscs' | 2 | import { buildAbsoluteFixturePath, root } from '../miscs/miscs' |
3 | import { isAbsolute, join } from 'path' | 3 | import { isAbsolute, join } from 'path' |
4 | import { parse } from 'url' | ||
5 | |||
6 | function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) { | ||
7 | const { host, protocol, pathname } = parse(url) | ||
8 | |||
9 | return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range }) | ||
10 | } | ||
4 | 11 | ||
5 | function makeGetRequest (options: { | 12 | function makeGetRequest (options: { |
6 | url: string, | 13 | url: string, |
7 | path: string, | 14 | path?: string, |
8 | query?: any, | 15 | query?: any, |
9 | token?: string, | 16 | token?: string, |
10 | statusCodeExpected?: number, | 17 | statusCodeExpected?: number, |
11 | contentType?: string | 18 | contentType?: string, |
19 | range?: string | ||
12 | }) { | 20 | }) { |
13 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 21 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 |
14 | if (options.contentType === undefined) options.contentType = 'application/json' | 22 | if (options.contentType === undefined) options.contentType = 'application/json' |
15 | 23 | ||
16 | const req = request(options.url) | 24 | const req = request(options.url).get(options.path) |
17 | .get(options.path) | ||
18 | 25 | ||
19 | if (options.contentType) req.set('Accept', options.contentType) | 26 | if (options.contentType) req.set('Accept', options.contentType) |
20 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | 27 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) |
21 | if (options.query) req.query(options.query) | 28 | if (options.query) req.query(options.query) |
29 | if (options.range) req.set('Range', options.range) | ||
22 | 30 | ||
23 | return req.expect(options.statusCodeExpected) | 31 | return req.expect(options.statusCodeExpected) |
24 | } | 32 | } |
@@ -164,5 +172,6 @@ export { | |||
164 | makePostBodyRequest, | 172 | makePostBodyRequest, |
165 | makePutBodyRequest, | 173 | makePutBodyRequest, |
166 | makeDeleteRequest, | 174 | makeDeleteRequest, |
175 | makeRawRequest, | ||
167 | updateAvatarRequest | 176 | updateAvatarRequest |
168 | } | 177 | } |