HttpProxyIntercept.java
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.github.monkeywie.proxyee.intercept;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
/**
* http拦截器
* beforeForward -> beforeRequest -> afterResponse
*/
public class HttpProxyIntercept {
/**
* 在与目标服务器建立连接之前拦截
*/
public void beforeConnect(Channel clientChannel, HttpProxyInterceptPipeline pipeline) throws Exception {
}
/**
* 拦截代理服务器到目标服务器的请求头
*/
public void beforeRequest(Channel clientChannel, HttpRequest httpRequest,
HttpProxyInterceptPipeline pipeline) throws Exception {
pipeline.beforeRequest(clientChannel, httpRequest);
}
/**
* 拦截代理服务器到目标服务器的请求体
*/
public void beforeRequest(Channel clientChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline) throws Exception {
pipeline.beforeRequest(clientChannel, httpContent);
}
/**
* 拦截代理服务器到客户端的响应头
*/
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse,
HttpProxyInterceptPipeline pipeline) throws Exception {
pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
}
/**
* 拦截代理服务器到客户端的响应体
*/
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline)
throws Exception {
pipeline.afterResponse(clientChannel, proxyChannel, httpContent);
}
}