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

Method build_redirect_response

src/proxy/http/HttpTransact.cc:8186–8242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8184}
8185
8186void
8187HttpTransact::build_redirect_response(State *s)
8188{
8189 TxnDbg(dbg_ctl_http_redirect, "Entering HttpTransact::build_redirect_response");
8190 URL *u;
8191 const char *old_host;
8192 int old_host_len;
8193 const char *new_url = nullptr;
8194 int new_url_len;
8195 char *to_free = nullptr;
8196
8197 HTTPStatus status_code = HTTP_STATUS_MOVED_TEMPORARILY;
8198 char *reason_phrase = const_cast<char *>(http_hdr_reason_lookup(status_code));
8199
8200 build_response(s, &s->hdr_info.client_response, s->client_info.http_version, status_code, reason_phrase);
8201
8202 //////////////////////////////////////////////////////////
8203 // figure out what new url should be. this little hack //
8204 // inserts expanded hostname into old url in order to //
8205 // get scheme information, then puts the old url back. //
8206 //////////////////////////////////////////////////////////
8207 u = s->hdr_info.client_request.url_get();
8208 old_host = u->host_get(&old_host_len);
8209 u->host_set(s->dns_info.lookup_name, strlen(s->dns_info.lookup_name));
8210 new_url = to_free = u->string_get(&s->arena, &new_url_len);
8211 if (new_url == nullptr) {
8212 new_url = "";
8213 }
8214 u->host_set(old_host, old_host_len);
8215
8216 //////////////////////////
8217 // set redirect headers //
8218 //////////////////////////
8219 HTTPHdr *h = &s->hdr_info.client_response;
8220 if (s->txn_conf->insert_response_via_string) {
8221 const char pa[] = "Proxy-agent";
8222
8223 h->value_append(pa, sizeof(pa) - 1, s->http_config_param->proxy_response_via_string,
8224 s->http_config_param->proxy_response_via_string_len);
8225 }
8226 h->value_set(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, new_url, new_url_len);
8227
8228 //////////////////////////
8229 // set descriptive text //
8230 //////////////////////////
8231 s->free_internal_msg_buffer();
8232 s->internal_msg_buffer_fast_allocator_size = -1;
8233 // template redirect#temporarily can not be used here since there is no way to pass the computed url to the template.
8234 s->internal_msg_buffer = body_factory->getFormat(8192, &s->internal_msg_buffer_size, "%s <a href=\"%s\">%s</a>. %s.",
8235 "The document you requested is now", new_url, new_url,
8236 "Please update your documents and bookmarks accordingly", nullptr);
8237
8238 h->set_content_length(s->internal_msg_buffer_size);
8239 h->value_set(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE, "text/html", 9);
8240
8241 s->arena.str_free(to_free);
8242}
8243

Callers

nothing calls this directly

Calls 11

http_hdr_reason_lookupFunction · 0.85
url_getMethod · 0.80
string_getMethod · 0.80
value_appendMethod · 0.80
getFormatMethod · 0.80
set_content_lengthMethod · 0.80
str_freeMethod · 0.80
host_getMethod · 0.45
host_setMethod · 0.45
value_setMethod · 0.45

Tested by

no test coverage detected