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

Method do_redirect

src/proxy/http/HttpSM.cc:8311–8375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8309}
8310
8311void
8312HttpSM::do_redirect()
8313{
8314 SMDbg(dbg_ctl_http_redirect, "enable_redirection %u", enable_redirection);
8315 if (!enable_redirection || redirection_tries >= t_state.txn_conf->number_of_redirections) {
8316 this->postbuf_clear();
8317
8318 if (enable_redirection && redirection_tries >= t_state.txn_conf->number_of_redirections) {
8319 t_state.squid_codes.subcode = SQUID_SUBCODE_NUM_REDIRECTIONS_EXCEEDED;
8320 }
8321
8322 return;
8323 }
8324
8325 // if redirect_url is set by an user's plugin, yts will redirect to this url anyway.
8326 if (is_redirect_required()) {
8327 if (redirect_url != nullptr || t_state.hdr_info.client_response.field_find(MIME_FIELD_LOCATION, MIME_LEN_LOCATION)) {
8328 if (Log::transaction_logging_enabled() && t_state.api_info.logging_enabled) {
8329 LogAccess accessor(this);
8330 if (redirect_url == nullptr) {
8331 if (t_state.squid_codes.log_code == SQUID_LOG_TCP_HIT) {
8332 t_state.squid_codes.log_code = SQUID_LOG_TCP_HIT_REDIRECT;
8333 } else {
8334 t_state.squid_codes.log_code = SQUID_LOG_TCP_MISS_REDIRECT;
8335 }
8336 } else {
8337 if (t_state.squid_codes.log_code == SQUID_LOG_TCP_HIT) {
8338 t_state.squid_codes.log_code = SQUID_LOG_TCP_HIT_X_REDIRECT;
8339 } else {
8340 t_state.squid_codes.log_code = SQUID_LOG_TCP_MISS_X_REDIRECT;
8341 }
8342 }
8343
8344 int ret = Log::access(&accessor);
8345
8346 if (ret & Log::FULL) {
8347 SMDbg(dbg_ctl_http, "Logging system indicates FULL.");
8348 }
8349 if (ret & Log::FAIL) {
8350 Log::error("failed to log transaction for at least one log object");
8351 }
8352 }
8353
8354 ++redirection_tries;
8355 if (redirect_url != nullptr) {
8356 redirect_request(redirect_url, redirect_url_len);
8357 ats_free((void *)redirect_url);
8358 redirect_url = nullptr;
8359 redirect_url_len = 0;
8360 Metrics::Counter::increment(http_rsb.total_x_redirect);
8361 } else {
8362 // get the location header and setup the redirect
8363 int redir_len = 0;
8364 char *redir_url =
8365 const_cast<char *>(t_state.hdr_info.client_response.value_get(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, &redir_len));
8366 redirect_request(redir_url, redir_len);
8367 }
8368

Callers

nothing calls this directly

Calls 6

postbuf_clearMethod · 0.95
errorFunction · 0.85
ats_freeFunction · 0.85
incrementFunction · 0.85
field_findMethod · 0.80
value_getMethod · 0.45

Tested by

no test coverage detected