@@ -46,26 +46,14 @@ export interface IBanditParametersResponse {
46
46
bandits : Record < string , BanditParameters > ;
47
47
}
48
48
49
- /**
50
- * Fixes issues with url.toString() in older React Native versions
51
- * that leaves a trailing slash in pathname
52
- * @param url URL to stringify
53
- * @returns stringified url
54
- */
55
- const urlWithNoTrailingSlash = ( url : URL ) => {
56
- // Note: URL.pathname does not exist in some React Native JS runtime
57
- // so we have to do string manipulation on the stringified URL
58
- return url . toString ( ) . replace ( / \/ \? / , '?' ) . replace ( / \/ $ / , '' ) ;
59
- } ;
60
-
61
49
export interface IHttpClient {
62
50
getUniversalFlagConfiguration ( ) : Promise < IUniversalFlagConfigResponse | undefined > ;
63
51
getBanditParameters ( ) : Promise < IBanditParametersResponse | undefined > ;
64
52
getPrecomputedFlags (
65
53
payload : PrecomputedFlagsPayload ,
66
54
) : Promise < IObfuscatedPrecomputedConfigurationResponse | undefined > ;
67
- rawGet < T > ( url : URL ) : Promise < T | undefined > ;
68
- rawPost < T , P > ( url : URL , payload : P ) : Promise < T | undefined > ;
55
+ rawGet < T > ( url : string ) : Promise < T | undefined > ;
56
+ rawPost < T , P > ( url : string , payload : P ) : Promise < T | undefined > ;
69
57
}
70
58
71
59
export default class FetchHttpClient implements IHttpClient {
@@ -94,14 +82,14 @@ export default class FetchHttpClient implements IHttpClient {
94
82
) ;
95
83
}
96
84
97
- async rawGet < T > ( url : URL ) : Promise < T | undefined > {
85
+ async rawGet < T > ( url : string ) : Promise < T | undefined > {
98
86
try {
99
87
// Canonical implementation of abortable fetch for interrupting when request takes longer than desired.
100
88
// https://developer.chrome.com/blog/abortable-fetch/#reacting_to_an_aborted_fetch
101
89
const controller = new AbortController ( ) ;
102
90
const signal = controller . signal ;
103
91
const timeoutId = setTimeout ( ( ) => controller . abort ( ) , this . timeout ) ;
104
- const response = await fetch ( urlWithNoTrailingSlash ( url ) , { signal } ) ;
92
+ const response = await fetch ( url , { signal } ) ;
105
93
// Clear timeout when response is received within the budget.
106
94
clearTimeout ( timeoutId ) ;
107
95
@@ -120,13 +108,13 @@ export default class FetchHttpClient implements IHttpClient {
120
108
}
121
109
}
122
110
123
- async rawPost < T , P > ( url : URL , payload : P ) : Promise < T | undefined > {
111
+ async rawPost < T , P > ( url : string , payload : P ) : Promise < T | undefined > {
124
112
try {
125
113
const controller = new AbortController ( ) ;
126
114
const signal = controller . signal ;
127
115
const timeoutId = setTimeout ( ( ) => controller . abort ( ) , this . timeout ) ;
128
116
129
- const response = await fetch ( urlWithNoTrailingSlash ( url ) , {
117
+ const response = await fetch ( url , {
130
118
method : 'POST' ,
131
119
headers : {
132
120
'Content-Type' : 'application/json' ,
0 commit comments