From b1abae7b7386f58761ac83e3af70620c15e0cb74 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Mon, 4 Feb 2019 15:47:34 -0300 Subject: [PATCH] Fix SSL_shutdown (#7372) * Add manual specs to perform https requests * Assume connection is closed when ssl_shutdown reports syscall error Based on d5fe700ee0dfa6856364f31650fb2331dcbfdaf2 * Cleanup unused code --- spec/manual/https_client_spec.cr | 15 +++++++++++++++ src/openssl/ssl/socket.cr | 17 ++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 spec/manual/https_client_spec.cr diff --git a/spec/manual/https_client_spec.cr b/spec/manual/https_client_spec.cr new file mode 100644 index 000000000000..3780a088cbc2 --- /dev/null +++ b/spec/manual/https_client_spec.cr @@ -0,0 +1,15 @@ +require "spec" +require "openssl" +require "http" + +describe "https requests" do + it "can fetch from google.com" do + HTTP::Client.get("https://google.com") + end + + it "can close request before consuming body" do + HTTP::Client.get("https://crystal-lang.org") do + break + end + end +end diff --git a/src/openssl/ssl/socket.cr b/src/openssl/ssl/socket.cr index d2489c7d9920..160f3cac0132 100644 --- a/src/openssl/ssl/socket.cr +++ b/src/openssl/ssl/socket.cr @@ -148,23 +148,14 @@ abstract class OpenSSL::SSL::Socket < IO ret = LibSSL.ssl_shutdown(@ssl) break if ret == 1 raise OpenSSL::SSL::Error.new(@ssl, ret, "SSL_shutdown") if ret < 0 - rescue e : Errno - case e.errno - when 0 - # OpenSSL claimed an underlying syscall failed, but that didn't set any error state, - # assume we're done - break - when Errno::EAGAIN - # Ignore/retry, shutdown did not complete yet - when Errno::EINPROGRESS - # Ignore/retry, another operation not complete yet - else - raise e - end rescue e : OpenSSL::SSL::Error case e.error when .want_read?, .want_write? # Ignore, shutdown did not complete yet + when .syscall? + # OpenSSL claimed an underlying syscall failed, but that didn't set any error state, + # assume we're done + break else raise e end