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

Method handle_request_keep_alive_headers

src/proxy/http/HttpTransact.cc:6789–6879  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////// void HttpTransact::handle_request_keep_alive_headers( State* s, bool ka_on, HTTPVersion ver, HTTPHdr *heads) Removes keep alive headers from user-agent from Adds the appropriate keep alive headers (if any) to for keep-alive state , and HTTP version . ///////////////////////////////////////////

Source from the content-addressed store, hash-verified

6787//
6788//////////////////////////////////////////////////////////////////////////////
6789void
6790HttpTransact::handle_request_keep_alive_headers(State *s, HTTPVersion ver, HTTPHdr *heads)
6791{
6792 enum KA_Action_t {
6793 KA_UNKNOWN,
6794 KA_DISABLED,
6795 KA_CLOSE,
6796 KA_CONNECTION,
6797 };
6798
6799 KA_Action_t ka_action = KA_UNKNOWN;
6800 bool upstream_ka = (s->current.server->keep_alive == HTTP_KEEPALIVE);
6801
6802 ink_assert(heads->type_get() == HTTP_TYPE_REQUEST);
6803
6804 // Check preconditions for Keep-Alive
6805 if (!upstream_ka) {
6806 ka_action = KA_DISABLED;
6807 } else if (ver.get_major() == 0) { /* No K-A for 0.9 apps */
6808 ka_action = KA_DISABLED;
6809 }
6810 // If preconditions are met, figure out what action to take
6811 if (ka_action == KA_UNKNOWN) {
6812 int method = heads->method_get_wksidx();
6813 if (method == HTTP_WKSIDX_GET || method == HTTP_WKSIDX_HEAD || method == HTTP_WKSIDX_OPTIONS || method == HTTP_WKSIDX_PURGE ||
6814 method == HTTP_WKSIDX_DELETE || method == HTTP_WKSIDX_TRACE) {
6815 // These methods do not need a content-length header
6816 ka_action = KA_CONNECTION;
6817 } else {
6818 // All remaining methods require a content length header
6819 if (heads->get_content_length() == -1) {
6820 ka_action = KA_CLOSE;
6821 } else {
6822 ka_action = KA_CONNECTION;
6823 }
6824 }
6825 }
6826
6827 ink_assert(ka_action != KA_UNKNOWN);
6828
6829 // Since connection headers are hop-to-hop, strip the
6830 // the ones we received from the user-agent
6831 heads->field_delete(MIME_FIELD_PROXY_CONNECTION, MIME_LEN_PROXY_CONNECTION);
6832 heads->field_delete(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION);
6833
6834 if (!s->is_upgrade_request) {
6835 // Insert K-A headers as necessary
6836 switch (ka_action) {
6837 case KA_CONNECTION:
6838 ink_assert(s->current.server->keep_alive != HTTP_NO_KEEPALIVE);
6839 if (ver == HTTP_1_0) {
6840 if (s->current.request_to == ResolveInfo::PARENT_PROXY && parent_is_proxy(s)) {
6841 heads->value_set(MIME_FIELD_PROXY_CONNECTION, MIME_LEN_PROXY_CONNECTION, "keep-alive", 10);
6842 } else {
6843 heads->value_set(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION, "keep-alive", 10);
6844 }
6845 }
6846 // NOTE: if the version is 1.1 we don't need to do

Callers

nothing calls this directly

Calls 9

parent_is_proxyFunction · 0.85
type_getMethod · 0.80
get_majorMethod · 0.80
method_get_wksidxMethod · 0.80
get_content_lengthMethod · 0.80
field_deleteMethod · 0.80
get_server_txnMethod · 0.80
value_setMethod · 0.45
set_close_connectionMethod · 0.45

Tested by

no test coverage detected