-
-
Notifications
You must be signed in to change notification settings - Fork 475
Expand file tree
/
Copy pathSentryRequestResolver.java
More file actions
70 lines (63 loc) · 2.56 KB
/
Copy pathSentryRequestResolver.java
File metadata and controls
70 lines (63 loc) · 2.56 KB
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
package io.sentry.spring.jakarta.webflux;
import com.jakewharton.nopen.annotation.Open;
import io.sentry.IScopes;
import io.sentry.protocol.Request;
import io.sentry.util.HttpUtils;
import io.sentry.util.Objects;
import io.sentry.util.UrlUtils;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
@Open
@ApiStatus.Experimental
public class SentryRequestResolver {
private final @NotNull IScopes scopes;
public SentryRequestResolver(final @NotNull IScopes scopes) {
this.scopes = Objects.requireNonNull(scopes, "scopes are required");
}
public @NotNull Request resolveSentryRequest(final @NotNull ServerHttpRequest httpRequest) {
final Request sentryRequest = new Request();
final String methodName =
httpRequest.getMethod() != null ? httpRequest.getMethod().name() : "unknown";
sentryRequest.setMethod(methodName);
final @NotNull URI uri = httpRequest.getURI();
final @NotNull UrlUtils.UrlDetails urlDetails = UrlUtils.parse(uri.toString());
urlDetails.applyToRequest(sentryRequest);
sentryRequest.setHeaders(resolveHeadersMap(httpRequest.getHeaders()));
if (scopes.getOptions().isSendDefaultPii()) {
String headerName = HttpUtils.COOKIE_HEADER_NAME;
sentryRequest.setCookies(
toString(
HttpUtils.filterOutSecurityCookiesFromHeader(
httpRequest.getHeaders().get(headerName), headerName, Collections.emptyList())));
}
return sentryRequest;
}
@NotNull
Map<String, String> resolveHeadersMap(final HttpHeaders request) {
final Map<String, String> headersMap = new HashMap<>();
for (Map.Entry<String, List<String>> entry : request.headerSet()) {
// do not copy personal information identifiable headers
String headerName = entry.getKey();
if (scopes.getOptions().isSendDefaultPii()
|| !HttpUtils.containsSensitiveHeader(headerName)) {
headersMap.put(
headerName,
toString(
HttpUtils.filterOutSecurityCookiesFromHeader(
entry.getValue(), headerName, Collections.emptyList())));
}
}
return headersMap;
}
private static @Nullable String toString(final @Nullable List<String> enumeration) {
return enumeration != null ? String.join(",", enumeration) : null;
}
}