Skip to content

Commit 658e3cd

Browse files
authored
Abstract adding Connection: close header to avoid triggering H2 draining logic (#8178)
1 parent 76c4bc0 commit 658e3cd

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

proxy/ProxyTransaction.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,11 @@ ProxyTransaction::allow_half_open() const
240240
{
241241
return false;
242242
}
243+
244+
// Most protocols will not want to set the Connection: header
245+
// For H2 it will initiate the drain logic. So we make do nothing
246+
// the default action.
247+
void
248+
ProxyTransaction::set_close_connection(HTTPHdr &hdr) const
249+
{
250+
}

proxy/ProxyTransaction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class ProxyTransaction : public VConnection
8787
// Returns true if there is a request body for this request
8888
virtual bool has_request_body(int64_t content_length, bool is_chunked_set) const;
8989

90+
// Worker function to set Connection:close header if appropriate for
91+
// underlying protocol
92+
virtual void set_close_connection(HTTPHdr &hdr) const;
93+
9094
sockaddr const *get_remote_addr() const;
9195

9296
virtual HTTPVersion get_version(HTTPHdr &hdr) const;

proxy/http/Http1Transaction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Http1Transaction : public ProxyTransaction
4343
// Methods
4444
int get_transaction_id() const override;
4545
void set_reader(IOBufferReader *reader);
46+
void set_close_connection(HTTPHdr &hdr) const override;
4647

4748
////////////////////
4849
// Variables
@@ -71,3 +72,9 @@ Http1Transaction::set_reader(IOBufferReader *reader)
7172
{
7273
_reader = reader;
7374
}
75+
76+
inline void
77+
Http1Transaction::set_close_connection(HTTPHdr &hdr) const
78+
{
79+
hdr.value_set(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION, "close", 5);
80+
}

proxy/http/HttpSM.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5873,7 +5873,7 @@ HttpSM::do_drain_request_body(HTTPHdr &response)
58735873

58745874
close_connection:
58755875
t_state.client_info.keep_alive = HTTP_NO_KEEPALIVE;
5876-
response.value_set(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION, "close", 5);
5876+
ua_txn->set_close_connection(response);
58775877
}
58785878

58795879
void

proxy/http/HttpTransact.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6891,7 +6891,10 @@ HttpTransact::handle_request_keep_alive_headers(State *s, HTTPVersion ver, HTTPH
68916891
if (s->current.request_to == PARENT_PROXY && parent_is_proxy(s)) {
68926892
heads->value_set(MIME_FIELD_PROXY_CONNECTION, MIME_LEN_PROXY_CONNECTION, "close", 5);
68936893
} else {
6894-
heads->value_set(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION, "close", 5);
6894+
ProxyTransaction *svr = s->state_machine->get_server_txn();
6895+
if (svr) {
6896+
svr->set_close_connection(*heads);
6897+
}
68956898
}
68966899
}
68976900
// Note: if we are 1.1, we always need to send the close
@@ -7050,7 +7053,11 @@ HttpTransact::handle_response_keep_alive_headers(State *s, HTTPVersion ver, HTTP
70507053
case KA_CLOSE:
70517054
case KA_DISABLED:
70527055
if (s->client_info.keep_alive != HTTP_NO_KEEPALIVE || (ver == HTTP_1_1)) {
7053-
heads->value_set(c_hdr_field_str, c_hdr_field_len, "close", 5);
7056+
if (s->client_info.proxy_connect_hdr) {
7057+
heads->value_set(c_hdr_field_str, c_hdr_field_len, "close", 5);
7058+
} else if (s->state_machine->ua_txn != nullptr) {
7059+
s->state_machine->ua_txn->set_close_connection(*heads);
7060+
}
70547061
s->client_info.keep_alive = HTTP_NO_KEEPALIVE;
70557062
}
70567063
// Note: if we are 1.1, we always need to send the close

0 commit comments

Comments
 (0)