###前提・実現したいこと
HTTPSでクライアント及びgoogle.comに接続するLプロキシを書こうとしたのですが、デバッグとして以下のコマンドでcurlで繋ごうとしたところ、エラーが出てしまいます。
curl -v --proxy-insecure -x https://localhost -L http://google.com
###発生している問題・エラーメッセージ
curlには以下のようなエラーが出ました。
* Rebuilt URL to: http://google.com/ * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 443 (#0) * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Client hello (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * Proxy certificate: * subject: // * start date: Oct 4 22:59:50 2017 GMT * expire date: Oct 4 22:59:50 2018 GMT * issuer: // * SSL certificate verify result: self signed certificate (18), continuing anyway. > GET http://google.com/ HTTP/1.1 > Host: google.com > User-Agent: curl/7.56.0 > Accept: */* > Proxy-Connection: Keep-Alive > < HTTP/1.1 302 Found < cache-control: private < content-type: text/html; charset=UTF-8 < referrer-policy: no-referrer < location: https://www.google.co.jp/?gfe_rd=cr&dcr=0&ei=SRrxWYrHMbHU8AeByq2ABg < content-length: 272 < date: Wed, 25 Oct 2017 23:12:09 GMT < alt-svc: quic=":443"; ma=2592000; v="39,38,37,35" < connection: close < * Closing connection 0 * TLSv1.2 (OUT), TLS alert, Client hello (1): * Issue another request to this URL: 'https://www.google.co.jp/?gfe_rd=cr&dcr=0&ei=SRrxWYrHMbHU8AeByq2ABg' * Hostname localhost was found in DNS cache * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 443 (#1) * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Client hello (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server accepted to use http/1.1 * Proxy certificate: * subject: //ここは隠します * start date: Oct 4 22:59:50 2017 GMT * expire date: Oct 4 22:59:50 2018 GMT * issuer: // ここは隠します * SSL certificate verify result: self signed certificate (18), continuing anyway. * allocate connect buffer! * Establish HTTP proxy tunnel to www.google.co.jp:443 > CONNECT www.google.co.jp:443 HTTP/1.1 > Host: www.google.co.jp:443 > User-Agent: curl/7.56.0 > Proxy-Connection: Keep-Alive > * Proxy CONNECT aborted * CONNECT phase completed! * Connection #1 to host localhost left intact curl: (56) Proxy CONNECT aborted
###該当のソースコード
javascript
1var httpProxy = require('http-proxy'); 2var fs = require('fs'); 3 4var config = { 5 port: process.env['PORT'], // 443 6 7 ssl: { 8 key: fs.readFileSync(__dirname + process.env['SSL_KEY'], 'utf8'), // ssl key 9 cert: fs.readFileSync(__dirname + process.env['SSL_CERT'], 'utf8') // ssl cert 10 } 11}; 12 13 14var proxy = httpProxy.createServer({ 15 ssl: config.ssl, 16 target: 'https://google.com', 17 secure: true 18}).listen(config.port); 19 20 21proxy.on('proxyReq', function (proxyReq, req, res) { 22 console.log('proxyReq'); 23}); 24 25proxy.on('proxyRes', function(proxyRes, req, res) { 26 console.log('proxyRes'); 27}); 28 29console.log('Server running at https://localhost:' + config.port);
###試したこと
実行してみたところ以下の文字列は表示されてましたので、最後にクライアントへのレスポンス送信がうまくいってないのかと思います。
proxyReq proxyRes
###補足情報(言語/FW/ツール等のバージョンなど)
- node.js
- docker, docker-compose
あなたの回答
tips
プレビュー