• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kiva / ui / 13861583877

14 Mar 2025 05:01PM UTC coverage: 46.746% (-0.03%) from 46.777%
13861583877

push

github

emuvente
fix: only set user-agent header if configured

1174 of 2586 branches covered (45.4%)

Branch coverage included in aggregate %.

1663 of 3483 relevant lines covered (47.75%)

383.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/api/HttpLink.js
1
import { BatchHttpLink } from '@apollo/client/link/batch-http/index';
2
import { HttpLink } from '@apollo/client/link/http/index';
3
import { split } from '@apollo/client/core/index';
4

5
export default ({
6
        uri = '',
×
7
        userAgent,
8
        fetch,
9
        apolloBatching,
10
        stellateDebugHeaders,
11
        stellateGraphqlUri,
12
        stellateCachedOperations,
13
}) => {
14
        // Note: we will have issues in the client and may need to check this too: uri.indexOf('stellate') > -1
15
        const onVm = uri.indexOf('vm') > -1 || uri.indexOf('local') > -1;
×
16

17
        const options = {
×
18
                uri,
19
                fetch,
20
                headers: {},
21
                credentials: 'same-origin',
22
                fetchOptions: {
23
                        // fix request blocked b/c of self-signed certificate on dev-vm.
24
                        strictSSL: !onVm,
25
                }
26
        };
27

28
        // Add user agent to headers if it exists
29
        if (userAgent) {
×
30
                options.headers['User-Agent'] = userAgent;
×
31
        }
32

33
        // Create a new options object for stellate
34
        const stellateOptions = {
×
35
                ...options,
36
                headers: stellateDebugHeaders ? {
×
37
                        ...options?.headers,
38
                        'gcdn-debug': 1,
39
                } : options.headers,
40
                uri: stellateGraphqlUri ?? uri,
×
41
        };
42

43
        // Format operations list into an arrayif it's not undefined or an empty string
44
        const cachableOperations = (stellateCachedOperations && stellateCachedOperations !== '')
×
45
                ? stellateCachedOperations?.split(',') : [];
46

47
        const link = split(
×
48
                operation => {
49
                        // check to see if we have a Stellate uri available
50
                        if (!stellateGraphqlUri || cachableOperations.length === 0) {
×
51
                                return false;
×
52
                        }
53
                        // check if the operation is cachable
54
                        if ((cachableOperations.includes(operation.operationName) || cachableOperations.includes('*'))
×
55
                                // only use stellate uri if the response is ok or undefined, retry failed queries to origin instead
56
                                && operation.getContext()?.response?.ok !== false) {
57
                                // update our options if we are caching the query
58
                                options.uri = stellateGraphqlUri;
×
59
                                return true;
×
60
                        }
61
                        // use default graphql uri
62
                        return false;
×
63
                },
64
                // eslint-disable-next-line max-len
65
                (!apolloBatching ? new HttpLink(stellateOptions) : new BatchHttpLink(stellateOptions)), // function returns TRUE use this
×
66
                (!apolloBatching ? new HttpLink(options) : new BatchHttpLink(options)), // function returns FALSE use this
×
67
        );
68

69
        return link;
×
70
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc