forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfba322
commit b6c78d5
Showing
10 changed files
with
435 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
client-runtime/src/main/java/com/microsoft/rest/BaseUrlInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* | ||
*/ | ||
|
||
package com.microsoft.rest; | ||
|
||
import java.io.IOException; | ||
|
||
import okhttp3.HttpUrl; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import okhttp3.internal.Version; | ||
import retrofit2.BaseUrl; | ||
|
||
/** | ||
* User agent interceptor for putting a 'User-Agent' header in the request. | ||
*/ | ||
public class BaseUrlInterceptor implements Interceptor { | ||
private String baseUrl; | ||
|
||
public BaseUrlInterceptor() { | ||
} | ||
|
||
public void setBaseUrl(String baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
if (baseUrl != null) { | ||
HttpUrl newUrl = request.url().newBuilder() | ||
.host(baseUrl) | ||
.build(); | ||
request = request.newBuilder() | ||
.url(newUrl) | ||
.build(); | ||
} | ||
return chain.proceed(request); | ||
} | ||
} |
Oops, something went wrong.