-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHttpsProxyServerInitializer.java
More file actions
50 lines (42 loc) · 1.71 KB
/
HttpsProxyServerInitializer.java
File metadata and controls
50 lines (42 loc) · 1.71 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
package com.arloor.forwardproxy;
import com.arloor.forwardproxy.monitor.GlobalTrafficMonitor;
import com.arloor.forwardproxy.ssl.SslContextFactory;
import com.arloor.forwardproxy.vo.Config;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpServerExpectContinueHandler;
import io.netty.handler.ssl.SslContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HttpsProxyServerInitializer extends ChannelInitializer<SocketChannel> {
private static final Logger log = LoggerFactory.getLogger(HttpsProxyServerInitializer.class);
private final Config.Ssl ssl;
private SslContext sslCtx;
public HttpsProxyServerInitializer(Config.Ssl ssl) {
this.ssl = ssl;
loadSslContext();
}
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(GlobalTrafficMonitor.getInstance());
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpResponseEncoder());
p.addLast(new HttpServerExpectContinueHandler());
// p.addLast(new LoggingHandler(LogLevel.INFO));
p.addLast(new HttpProxyConnectHandler(ssl.getAuthMap()));
}
public void loadSslContext() {
try {
this.sslCtx = SslContextFactory.getSSLContext(ssl.getFullchain(), ssl.getPrivkey());
} catch (Throwable e) {
log.error("init ssl context error!", e);
}
}
}