(byte[] data)
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public byte[] onChunkReceived(byte[] data) throws Exception { |
| 68 | byte[] result = new byte[]{}; |
| 69 | synchronized (client_loopback) { |
| 70 | |
| 71 | Http http = Http.create(data); |
| 72 | // System.out.println(String.format("%s: %s:%s", http.getMethod(), |
| 73 | // http.getServerName(), http.getServerPort())); |
| 74 | |
| 75 | if (http.getMethod().equals("CONNECT")) { |
| 76 | |
| 77 | // HTTP2対応の都合上、ALPNを早期に確定する必要がある。 |
| 78 | // そのため、早めに「connection established」を返すことで、早めにSSLハンドシェイクを実施できるよう準備する。 |
| 79 | client_loopback |
| 80 | .sendWithoutRecording("HTTP/1.0 200 Connection Established\r\n\r\n".getBytes()); |
| 81 | |
| 82 | String serverName = http.getServerName(); |
| 83 | if (serverName.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")) { |
| 84 | |
| 85 | serverName = Https.getCommonName(http.getServerAddr()); |
| 86 | log("Overwrite CN: %s --> %s", http.getServerName(), serverName); |
| 87 | } |
| 88 | |
| 89 | if (SSLPassThroughs.getInstance().includes(serverName, listen_info.getPort())) { |
| 90 | |
| 91 | SocketEndpoint server_e = new SocketEndpoint(http.getServerAddr()); |
| 92 | SocketEndpoint client_e = new SocketEndpoint(client); |
| 93 | DuplexAsync d = new DuplexAsync(client_e, server_e); |
| 94 | d.start(); |
| 95 | |
| 96 | } else { |
| 97 | |
| 98 | SSLSocketEndpoint clientE; |
| 99 | SSLSocketEndpoint serverE; |
| 100 | if (listen_info.getServer() != null) { // upstream proxyに接続する時 |
| 101 | |
| 102 | SSLSocketEndpoint[] es = EndpointFactory.createBothSideSSLEndpoints(client, |
| 103 | null, http.getServerAddr(), listen_info.getServer().getAddress(), |
| 104 | http.getServerName(), listen_info.getCA().get()); |
| 105 | clientE = es[0]; |
| 106 | serverE = es[1]; |
| 107 | } else { // 直接サーバに接続する時 |
| 108 | |
| 109 | SSLSocketEndpoint[] es = EndpointFactory.createBothSideSSLEndpoints(client, |
| 110 | null, http.getServerAddr(), null, http.getServerName(), |
| 111 | listen_info.getCA().get()); |
| 112 | clientE = es[0]; |
| 113 | serverE = es[1]; |
| 114 | } |
| 115 | String ALPN = clientE.getApplicationProtocol(); |
| 116 | if (ALPN == null || ALPN.length() == 0) { |
| 117 | |
| 118 | /* The client does not support ALPN. It seems to be an old HTTP client */ |
| 119 | ALPN = "http/1.1"; |
| 120 | } |
| 121 | Server serverSetting = Servers.getInstance().queryByAddress(http.getServerAddr()); |
| 122 | String encoderName = (serverSetting != null) ? serverSetting.getEncoder() : "HTTP"; |
| 123 | DuplexAsync d = DuplexFactory.createDuplexAsync(clientE, serverE, encoderName, |
nothing calls this directly
no test coverage detected