Skip to content

Commit 9b3b3f4

Browse files
committed
ensure-url-end-with-slash
1 parent 5fdfd58 commit 9b3b3f4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/RestAnalyticsProvider.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ public Client(String baseUrl, List<AuthenticationProvider> authenticationProvide
514514

515515
var jacksonFactory = JacksonConverterFactory.create(createObjectMapper());
516516

517+
baseUrl = ensureEndsWithSlash(baseUrl);
518+
517519
Retrofit retrofit = new Retrofit.Builder()
518520
.baseUrl(baseUrl)
519521
.client(okHttpClient)
@@ -526,6 +528,17 @@ public Client(String baseUrl, List<AuthenticationProvider> authenticationProvide
526528
analyticsProvider = retrofit.create(AnalyticsProviderRetrofit.class);
527529
}
528530

531+
private String ensureEndsWithSlash(String baseUrl) {
532+
//if url contains path it must end with slash.
533+
//retrofit will check that in retrofit2.Retrofit.Builder.baseUrl(okhttp3.HttpUrl)
534+
var url = HttpUrl.get(baseUrl);
535+
List<String> pathSegments = url.pathSegments();
536+
if (!"".equals(pathSegments.get(pathSegments.size() - 1))) {
537+
return baseUrl + "/";
538+
}
539+
return baseUrl;
540+
}
541+
529542
private void addPerformanceInterceptor(OkHttpClient.Builder builder) {
530543
builder.addInterceptor(chain -> {
531544
PERFORMANCE.remove();

0 commit comments

Comments
 (0)