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