@@ -4,42 +4,41 @@ const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): Observab
4
4
username: resolve(options, config.USERNAME),
5
5
password: resolve(options, config.PASSWORD),
6
6
additionalHeaders: resolve(options, config.HEADERS),
7
- })
8
- .pipe(
9
- map(({ token, username, password, additionalHeaders }) => {
10
- const headers = Object.entries({
11
- Accept: 'application/json',
12
- ...additionalHeaders,
13
- ...options.headers,
14
- })
15
- .filter(([_, value]) => isDefined(value))
16
- .reduce((headers, [key, value]) => ({
17
- ...headers,
18
- [key]: String(value),
19
- }), {} as Record<string , string>);
7
+ }).pipe(
8
+ map(({ token, username, password, additionalHeaders }) => {
9
+ const headers = Object.entries({
10
+ Accept: 'application/json',
11
+ ...additionalHeaders,
12
+ ...options.headers,
13
+ })
14
+ .filter(([_, value]) => isDefined(value))
15
+ .reduce((headers, [key, value]) => ({
16
+ ...headers,
17
+ [key]: String(value),
18
+ }), {} as Record<string , string>);
20
19
21
- if (isStringWithValue(token)) {
22
- headers['Authorization'] = `Bearer ${token}`;
23
- }
20
+ if (isStringWithValue(token)) {
21
+ headers['Authorization'] = `Bearer ${token}`;
22
+ }
24
23
25
- if (isStringWithValue(username) && isStringWithValue(password)) {
26
- const credentials = base64(`${username}:${password}`);
27
- headers['Authorization'] = `Basic ${credentials}`;
28
- }
24
+ if (isStringWithValue(username) && isStringWithValue(password)) {
25
+ const credentials = base64(`${username}:${password}`);
26
+ headers['Authorization'] = `Basic ${credentials}`;
27
+ }
29
28
30
- if (options.body) {
31
- if (options.mediaType) {
32
- headers['Content-Type'] = options.mediaType;
33
- } else if (isBlob(options.body)) {
34
- headers['Content-Type'] = options.body.type || 'application/octet-stream';
35
- } else if (isString(options.body)) {
36
- headers['Content-Type'] = 'text/plain';
37
- } else if (!isFormData(options.body)) {
38
- headers['Content-Type'] = 'application/json';
39
- }
29
+ if (options.body) {
30
+ if (options.mediaType) {
31
+ headers['Content-Type'] = options.mediaType;
32
+ } else if (isBlob(options.body)) {
33
+ headers['Content-Type'] = options.body.type || 'application/octet-stream';
34
+ } else if (isString(options.body)) {
35
+ headers['Content-Type'] = 'text/plain';
36
+ } else if (!isFormData(options.body)) {
37
+ headers['Content-Type'] = 'application/json';
40
38
}
39
+ }
41
40
42
- return new HttpHeaders(headers);
43
- })
44
- );
41
+ return new HttpHeaders(headers);
42
+ }),
43
+ );
45
44
};
0 commit comments