MCPcopy Create free account
hub / github.com/apache/trafficserver / handle_response_keep_alive_headers

Method handle_response_keep_alive_headers

src/proxy/http/HttpTransact.cc:6894–7033  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////// void HttpTransact::handle_response_keep_alive_headers( State* s, bool ka_on, HTTPVersion ver, HTTPHdr *heads) Removes keep alive headers from origin server from Adds the appropriate Transfer-Encoding: chunked header. Adds the appropriate keep alive headers (if any) to for keep-alive state , and HTT

Source from the content-addressed store, hash-verified

6892//
6893//////////////////////////////////////////////////////////////////////////////
6894void
6895HttpTransact::handle_response_keep_alive_headers(State *s, HTTPVersion ver, HTTPHdr *heads)
6896{
6897 enum KA_Action_t {
6898 KA_UNKNOWN,
6899 KA_DISABLED,
6900 KA_CLOSE,
6901 KA_CONNECTION,
6902 };
6903 KA_Action_t ka_action = KA_UNKNOWN;
6904
6905 ink_assert(heads->type_get() == HTTP_TYPE_RESPONSE);
6906
6907 // Since connection headers are hop-to-hop, strip the
6908 // the ones we received from upstream
6909 heads->field_delete(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION);
6910 heads->field_delete(MIME_FIELD_PROXY_CONNECTION, MIME_LEN_PROXY_CONNECTION);
6911
6912 // Handle the upgrade cases
6913 if (s->is_upgrade_request && heads->status_get() == HTTP_STATUS_SWITCHING_PROTOCOL && s->source == SOURCE_HTTP_ORIGIN_SERVER) {
6914 s->client_info.keep_alive = HTTP_NO_KEEPALIVE;
6915 if (s->is_websocket) {
6916 TxnDbg(dbg_ctl_http_trans, "transaction successfully upgraded to websockets.");
6917 // s->transparent_passthrough = true;
6918 heads->value_set(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION, MIME_FIELD_UPGRADE, MIME_LEN_UPGRADE);
6919 heads->value_set(MIME_FIELD_UPGRADE, MIME_LEN_UPGRADE, "websocket", 9);
6920 }
6921
6922 // We set this state so that we can jump to our blind forwarding state once
6923 // the response is sent to the client.
6924 s->did_upgrade_succeed = true;
6925 return;
6926 }
6927
6928 int c_hdr_field_len;
6929 const char *c_hdr_field_str;
6930 if (s->client_info.proxy_connect_hdr) {
6931 c_hdr_field_str = MIME_FIELD_PROXY_CONNECTION;
6932 c_hdr_field_len = MIME_LEN_PROXY_CONNECTION;
6933 } else {
6934 c_hdr_field_str = MIME_FIELD_CONNECTION;
6935 c_hdr_field_len = MIME_LEN_CONNECTION;
6936 }
6937
6938 // Check pre-conditions for keep-alive
6939 if (ver.get_major() == 0) { /* No K-A for 0.9 apps */
6940 ka_action = KA_DISABLED;
6941 } else if (heads->status_get() == HTTP_STATUS_NO_CONTENT &&
6942 ((s->source == SOURCE_HTTP_ORIGIN_SERVER && s->current.server->transfer_encoding != NO_TRANSFER_ENCODING) ||
6943 heads->get_content_length() != 0)) {
6944 // some systems hang until the connection closes when receiving a 204 regardless of the K-A headers
6945 // close if there is any body response from the origin
6946 ka_action = KA_CLOSE;
6947 } else {
6948 // Determine if we are going to send either a server-generated or
6949 // proxy-generated chunked response to the client. If we cannot
6950 // trust the content-length, we may be able to chunk the response
6951 // to the client to keep the connection alive.

Callers

nothing calls this directly

Calls 12

type_getMethod · 0.80
field_deleteMethod · 0.80
get_majorMethod · 0.80
get_content_lengthMethod · 0.80
get_ua_txnMethod · 0.80
value_appendMethod · 0.80
status_getMethod · 0.45
value_setMethod · 0.45
validMethod · 0.45
set_close_connectionMethod · 0.45

Tested by

no test coverage detected