|
10 | 10 |
|
11 | 11 | import com.franmontiel.persistentcookiejar.PersistentCookieJar; |
12 | 12 | import com.franmontiel.persistentcookiejar.cache.SetCookieCache; |
| 13 | +import com.proxerme.library.BuildConfig; |
13 | 14 | import com.proxerme.library.info.ProxerUrlHolder; |
14 | 15 | import com.proxerme.library.util.SaveAllSharedPrefCookiePersistor; |
15 | 16 | import com.squareup.moshi.JsonDataException; |
@@ -306,10 +307,12 @@ public interface ErrorListener { |
306 | 307 | public static class Builder { |
307 | 308 |
|
308 | 309 | private static final String API_KEY_HEADER = "proxer-api-key"; |
| 310 | + private static final String USER_AGENT_HEADER = "User-Agent"; |
309 | 311 |
|
310 | 312 | private String apiKey; |
311 | 313 | private Context context; |
312 | 314 | private boolean deliverCancelledRequests; |
| 315 | + private String userAgent = "ProxerLibAndroid/" + BuildConfig.VERSION_NAME; |
313 | 316 |
|
314 | 317 | private Moshi moshi; |
315 | 318 | private CookieJar cookieJar; |
@@ -382,6 +385,12 @@ public Builder withCustomOkHttp(OkHttpClient httpClient) { |
382 | 385 | return this; |
383 | 386 | } |
384 | 387 |
|
| 388 | + public Builder withCustomUserAgent(String userAgent) { |
| 389 | + this.userAgent = userAgent; |
| 390 | + |
| 391 | + return this; |
| 392 | + } |
| 393 | + |
385 | 394 | /** |
386 | 395 | * Allows to set if requests should be delivered on the errorCallback if they have been |
387 | 396 | * cancelled. |
@@ -425,13 +434,21 @@ public Response intercept(Chain chain) throws IOException { |
425 | 434 | if (chain.request().url().host() |
426 | 435 | .equals(ProxerUrlHolder.getBaseApiHost().host())) { |
427 | 436 | return chain.proceed(chain.request().newBuilder() |
428 | | - .addHeader(API_KEY_HEADER, apiKey) |
| 437 | + .header(API_KEY_HEADER, apiKey) |
429 | 438 | .build()); |
430 | 439 | } else { |
431 | 440 | return chain.proceed(chain.request()); |
432 | 441 | } |
433 | 442 | } |
434 | 443 | }) |
| 444 | + .addInterceptor(new Interceptor() { |
| 445 | + @Override |
| 446 | + public Response intercept(Chain chain) throws IOException { |
| 447 | + return chain.proceed(chain.request().newBuilder() |
| 448 | + .header(USER_AGENT_HEADER, userAgent) |
| 449 | + .build()); |
| 450 | + } |
| 451 | + }) |
435 | 452 | .build(); |
436 | 453 | } |
437 | 454 | } |
|
0 commit comments