()
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void run() { |
| 48 | List<Socket> clients = new ArrayList<Socket>(); |
| 49 | while (!listen_socket.isClosed()) { |
| 50 | |
| 51 | try { |
| 52 | |
| 53 | final Socket client = listen_socket.accept(); |
| 54 | clients.add(client); |
| 55 | log("accept"); |
| 56 | |
| 57 | final Simplex client_loopback = new Simplex(client.getInputStream(), client.getOutputStream()); |
| 58 | |
| 59 | client_loopback.addSimplexEventListener(new SimplexEventAdapter() { |
| 60 | |
| 61 | @Override |
| 62 | public int onPacketReceived(byte[] data) throws Exception { |
| 63 | return Http.parseHttpDelimiter(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(), |
nothing calls this directly
no test coverage detected