-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathintegration-headers.ts
34 lines (30 loc) · 1.12 KB
/
integration-headers.ts
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
import type { Request } from 'express';
const ORIGIN = 'origin';
const httpMatcher = /^https?:\/\//;
const userAgentMatches = [
{ label: 'Axios', matcher: /^axios/ },
{ label: 'Curl', matcher: /^curl/ },
{ label: 'Go', matcher: /^Go-http-client/ },
{ label: 'Python', matcher: /^python-requests/ },
{ label: 'Node', matcher: /^node/ },
{ label: 'Java', matcher: /^Apache-HttpClient.*Java/ },
{ label: 'JiraCloudUnleash', matcher: /^Jira-Cloud-Unleash/ },
{ label: 'TerraformUnleash', matcher: /^Terraform-Provider-Unleash/ },
{ label: 'OpenAPIGO', matcher: /^OpenAPI-Generator\/.*\/go/ },
{ label: 'RestClientRuby', matcher: /^rest-client\/.*ruby/ },
];
export const getFilteredOrigin = (request: Request): string | undefined => {
const origin = request.headers[ORIGIN];
if (origin && httpMatcher.test(origin)) {
return origin;
}
return undefined;
};
export const determineIntegrationSource = (
userAgent: string,
): string | undefined => {
return (
userAgentMatches.find((candidate) => candidate.matcher.test(userAgent))
?.label ?? 'Other'
);
};