-
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
Showing
10 changed files
with
65 additions
and
17 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
2 changes: 1 addition & 1 deletion
2
.../yhy/http/pigeon/offer/GsonConverter.java → ...y/http/pigeon/internal/GsonConverter.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
2 changes: 1 addition & 1 deletion
2
...y/http/pigeon/offer/GuavaCallAdapter.java → ...ttp/pigeon/internal/GuavaCallAdapter.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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/yhy/http/pigeon/internal/HeaderInterceptor.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,44 @@ | ||
package com.yhy.http.pigeon.internal; | ||
|
||
import okhttp3.Headers; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* author : 颜洪毅 | ||
* e-mail : yhyzgn@gmail.com | ||
* time : 2020-08-29 19:40 | ||
* version: 1.0.0 | ||
* desc : 公共请求头专用拦截器 | ||
*/ | ||
public class HeaderInterceptor implements Interceptor { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(HeaderInterceptor.class); | ||
|
||
private final Map<String, String> headers; | ||
|
||
public HeaderInterceptor(Map<String, String> headers) { | ||
this.headers = headers; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Response intercept(@NotNull Chain chain) throws IOException { | ||
Request original = chain.request(); | ||
// 重建 request 并注入 全局请求头 | ||
Headers.Builder builder = original.headers().newBuilder(); | ||
headers.forEach((name, value) -> { | ||
LOGGER.debug("Setting global request header: {} = {}", name, value); | ||
builder.set(name, value); | ||
}); | ||
Request request = original.newBuilder().headers(builder.build()).build(); | ||
// 继续请求 | ||
return chain.proceed(request); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...p/pigeon/offer/HttpLoggerInterceptor.java → ...igeon/internal/HttpLoggerInterceptor.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
2 changes: 1 addition & 1 deletion
2
...y/http/pigeon/offer/JacksonConverter.java → ...ttp/pigeon/internal/JacksonConverter.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
2 changes: 1 addition & 1 deletion
2
...pigeon/offer/StringResponseConverter.java → ...eon/internal/StringResponseConverter.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
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