|
|
|
@ -37,14 +37,15 @@ |
|
|
|
|
#include "src/core/handshaker/handshaker.h" |
|
|
|
|
#include "src/core/handshaker/handshaker_registry.h" |
|
|
|
|
#include "src/core/handshaker/tcp_connect/tcp_connect_handshaker.h" |
|
|
|
|
#include "src/core/lib/address_utils/sockaddr_utils.h" |
|
|
|
|
#include "src/core/lib/channel/channel_args.h" |
|
|
|
|
#include "src/core/lib/channel/channel_args_preconditioning.h" |
|
|
|
|
#include "src/core/lib/config/core_configuration.h" |
|
|
|
|
#include "src/core/lib/event_engine/tcp_socket_utils.h" |
|
|
|
|
#include "src/core/lib/gprpp/status_helper.h" |
|
|
|
|
#include "src/core/lib/iomgr/endpoint.h" |
|
|
|
|
#include "src/core/lib/iomgr/iomgr_internal.h" |
|
|
|
|
#include "src/core/lib/iomgr/pollset_set.h" |
|
|
|
|
#include "src/core/lib/iomgr/resolve_address.h" |
|
|
|
|
#include "src/core/lib/resource_quota/api.h" |
|
|
|
|
#include "src/core/lib/security/credentials/credentials.h" |
|
|
|
|
#include "src/core/lib/security/security_connector/security_connector.h" |
|
|
|
@ -57,9 +58,6 @@ namespace grpc_core { |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
using grpc_event_engine::experimental::EventEngine; |
|
|
|
|
using grpc_event_engine::experimental::ResolvedAddressToURI; |
|
|
|
|
|
|
|
|
|
grpc_httpcli_get_override g_get_override; |
|
|
|
|
grpc_httpcli_post_override g_post_override; |
|
|
|
|
grpc_httpcli_put_override g_put_override; |
|
|
|
@ -174,10 +172,7 @@ HttpRequest::HttpRequest( |
|
|
|
|
pollent_(pollent), |
|
|
|
|
pollset_set_(grpc_pollset_set_create()), |
|
|
|
|
test_only_generate_response_(std::move(test_only_generate_response)), |
|
|
|
|
resolver_( |
|
|
|
|
ChannelArgs::FromC(channel_args_) |
|
|
|
|
.GetObjectRef<EventEngine>() |
|
|
|
|
->GetDNSResolver(EventEngine::DNSResolver::ResolverOptions())) { |
|
|
|
|
resolver_(GetDNSResolver()) { |
|
|
|
|
grpc_http_parser_init(&parser_, GRPC_HTTP_RESPONSE, response); |
|
|
|
|
grpc_slice_buffer_init(&incoming_); |
|
|
|
|
grpc_slice_buffer_init(&outgoing_); |
|
|
|
@ -211,14 +206,11 @@ void HttpRequest::Start() { |
|
|
|
|
test_only_generate_response_.value()(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!resolver_.ok()) { |
|
|
|
|
Finish(resolver_.status()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Ref().release(); // ref held by pending DNS resolution
|
|
|
|
|
(*resolver_) |
|
|
|
|
->LookupHostname(absl::bind_front(&HttpRequest::OnResolved, this), |
|
|
|
|
uri_.authority(), uri_.scheme()); |
|
|
|
|
dns_request_handle_ = resolver_->LookupHostname( |
|
|
|
|
absl::bind_front(&HttpRequest::OnResolved, this), uri_.authority(), |
|
|
|
|
uri_.scheme(), kDefaultDNSRequestTimeout, pollset_set_, |
|
|
|
|
/*name_server=*/""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HttpRequest::Orphan() { |
|
|
|
@ -227,8 +219,10 @@ void HttpRequest::Orphan() { |
|
|
|
|
CHECK(!cancelled_); |
|
|
|
|
cancelled_ = true; |
|
|
|
|
// cancel potentially pending DNS resolution.
|
|
|
|
|
if (*resolver_ != nullptr) { |
|
|
|
|
resolver_->reset(); |
|
|
|
|
if (dns_request_handle_.has_value() && |
|
|
|
|
resolver_->Cancel(dns_request_handle_.value())) { |
|
|
|
|
Finish(GRPC_ERROR_CREATE("cancelled during DNS resolution")); |
|
|
|
|
Unref(); |
|
|
|
|
} |
|
|
|
|
if (handshake_mgr_ != nullptr) { |
|
|
|
|
// Shutdown will cancel any ongoing tcp connect.
|
|
|
|
@ -244,7 +238,8 @@ void HttpRequest::AppendError(grpc_error_handle error) { |
|
|
|
|
if (overall_error_.ok()) { |
|
|
|
|
overall_error_ = GRPC_ERROR_CREATE("Failed HTTP/1 client request"); |
|
|
|
|
} |
|
|
|
|
auto addr_text = ResolvedAddressToURI(addresses_[next_address_ - 1]); |
|
|
|
|
const grpc_resolved_address* addr = &addresses_[next_address_ - 1]; |
|
|
|
|
auto addr_text = grpc_sockaddr_to_uri(addr); |
|
|
|
|
if (addr_text.ok()) error = AddMessagePrefix(*addr_text, std::move(error)); |
|
|
|
|
overall_error_ = grpc_error_add_child(overall_error_, std::move(error)); |
|
|
|
|
} |
|
|
|
@ -314,7 +309,7 @@ void HttpRequest::OnHandshakeDone(absl::StatusOr<HandshakerArgs*> result) { |
|
|
|
|
StartWrite(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HttpRequest::DoHandshake(const EventEngine::ResolvedAddress& addr) { |
|
|
|
|
void HttpRequest::DoHandshake(const grpc_resolved_address* addr) { |
|
|
|
|
// Create the security connector using the credentials and target name.
|
|
|
|
|
ChannelArgs args = ChannelArgs::FromC(channel_args_); |
|
|
|
|
RefCountedPtr<grpc_channel_security_connector> sc = |
|
|
|
@ -325,7 +320,7 @@ void HttpRequest::DoHandshake(const EventEngine::ResolvedAddress& addr) { |
|
|
|
|
&overall_error_, 1)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
absl::StatusOr<std::string> address = ResolvedAddressToURI(addr); |
|
|
|
|
absl::StatusOr<std::string> address = grpc_sockaddr_to_uri(addr); |
|
|
|
|
if (!address.ok()) { |
|
|
|
|
Finish(GRPC_ERROR_CREATE_REFERENCING("Failed to extract URI from address", |
|
|
|
|
&overall_error_, 1)); |
|
|
|
@ -358,16 +353,15 @@ void HttpRequest::NextAddress(grpc_error_handle error) { |
|
|
|
|
&overall_error_, 1)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
DoHandshake(addresses_[next_address_++]); |
|
|
|
|
const grpc_resolved_address* addr = &addresses_[next_address_++]; |
|
|
|
|
DoHandshake(addr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HttpRequest::OnResolved( |
|
|
|
|
absl::StatusOr<std::vector<EventEngine::ResolvedAddress>> addresses_or) { |
|
|
|
|
ApplicationCallbackExecCtx callback_exec_ctx; |
|
|
|
|
ExecCtx exec_ctx; |
|
|
|
|
absl::StatusOr<std::vector<grpc_resolved_address>> addresses_or) { |
|
|
|
|
RefCountedPtr<HttpRequest> unreffer(this); |
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
resolver_->reset(); |
|
|
|
|
dns_request_handle_.reset(); |
|
|
|
|
if (cancelled_) { |
|
|
|
|
Finish(GRPC_ERROR_CREATE("cancelled during DNS resolution")); |
|
|
|
|
return; |
|
|
|
|