4
4
import java .net .URI ;
5
5
import java .util .HashMap ;
6
6
import java .util .Map ;
7
+ import org .jetbrains .annotations .ApiStatus ;
7
8
import org .jetbrains .annotations .NotNull ;
9
+ import org .jetbrains .annotations .Nullable ;
8
10
9
11
/** Resolves {@link RequestDetails}. */
10
- final class RequestDetailsResolver {
12
+ @ ApiStatus .Experimental
13
+ public final class RequestDetailsResolver {
11
14
/** HTTP Header for the user agent. */
12
15
private static final String USER_AGENT = "User-Agent" ;
13
16
/** HTTP Header for the authentication to Sentry. */
14
17
private static final String SENTRY_AUTH = "X-Sentry-Auth" ;
15
18
16
- private final @ NotNull SentryOptions options ;
19
+ private final @ NotNull Dsn dsn ;
20
+ private final @ Nullable String sentryClientName ;
17
21
22
+ public RequestDetailsResolver (
23
+ final @ NotNull String dsn , final @ Nullable String sentryClientName ) {
24
+ Objects .requireNonNull (dsn , "dsn is required" );
25
+
26
+ this .dsn = new Dsn (dsn );
27
+ this .sentryClientName = sentryClientName ;
28
+ }
29
+
30
+ @ ApiStatus .Internal
18
31
public RequestDetailsResolver (final @ NotNull SentryOptions options ) {
19
- this .options = Objects .requireNonNull (options , "options is required" );
32
+ Objects .requireNonNull (options , "options is required" );
33
+
34
+ this .dsn = options .retrieveParsedDsn ();
35
+ this .sentryClientName = options .getSentryClientName ();
20
36
}
21
37
22
38
@ NotNull
23
- RequestDetails resolve () {
24
- final Dsn dsn = options .retrieveParsedDsn ();
39
+ public RequestDetails resolve () {
25
40
final URI sentryUri = dsn .getSentryUri ();
26
41
final String envelopeUrl = sentryUri .resolve (sentryUri .getPath () + "/envelope/" ).toString ();
27
42
@@ -33,15 +48,14 @@ RequestDetails resolve() {
33
48
+ SentryClient .SENTRY_PROTOCOL_VERSION
34
49
+ ","
35
50
+ "sentry_client="
36
- + options . getSentryClientName ()
51
+ + sentryClientName
37
52
+ ","
38
53
+ "sentry_key="
39
54
+ publicKey
40
55
+ (secretKey != null && secretKey .length () > 0 ? (",sentry_secret=" + secretKey ) : "" );
41
- final String userAgent = options .getSentryClientName ();
42
56
43
57
final Map <String , String > headers = new HashMap <>();
44
- headers .put (USER_AGENT , userAgent );
58
+ headers .put (USER_AGENT , sentryClientName );
45
59
headers .put (SENTRY_AUTH , authHeader );
46
60
47
61
return new RequestDetails (envelopeUrl , headers );
0 commit comments