| 8375 | } |
| 8376 | |
| 8377 | void |
| 8378 | HttpSM::redirect_request(const char *arg_redirect_url, const int arg_redirect_len) |
| 8379 | { |
| 8380 | SMDbg(dbg_ctl_http_redirect, "redirect url: %.*s", arg_redirect_len, arg_redirect_url); |
| 8381 | // get a reference to the client request header and client url and check to see if the url is valid |
| 8382 | HTTPHdr &clientRequestHeader = t_state.hdr_info.client_request; |
| 8383 | URL &clientUrl = *clientRequestHeader.url_get(); |
| 8384 | if (!clientUrl.valid()) { |
| 8385 | return; |
| 8386 | } |
| 8387 | |
| 8388 | bool valid_origHost = true; |
| 8389 | int origHost_len, origMethod_len; |
| 8390 | char origHost[MAXDNAME]; |
| 8391 | char origMethod[255]; |
| 8392 | int origPort = 80; |
| 8393 | |
| 8394 | if (t_state.hdr_info.server_request.valid()) { |
| 8395 | char *tmpOrigHost; |
| 8396 | |
| 8397 | origPort = t_state.hdr_info.server_request.port_get(); |
| 8398 | tmpOrigHost = const_cast<char *>(t_state.hdr_info.server_request.value_get(MIME_FIELD_HOST, MIME_LEN_HOST, &origHost_len)); |
| 8399 | |
| 8400 | if (tmpOrigHost) { |
| 8401 | memcpy(origHost, tmpOrigHost, origHost_len); |
| 8402 | origHost[std::min(origHost_len, MAXDNAME - 1)] = '\0'; |
| 8403 | } else { |
| 8404 | valid_origHost = false; |
| 8405 | } |
| 8406 | |
| 8407 | char *tmpOrigMethod = const_cast<char *>(t_state.hdr_info.server_request.method_get(&origMethod_len)); |
| 8408 | if (tmpOrigMethod) { |
| 8409 | memcpy(origMethod, tmpOrigMethod, std::min(origMethod_len, static_cast<int>(sizeof(origMethod)))); |
| 8410 | } else { |
| 8411 | valid_origHost = false; |
| 8412 | } |
| 8413 | } else { |
| 8414 | SMDbg(dbg_ctl_http_redir_error, "t_state.hdr_info.server_request not valid"); |
| 8415 | valid_origHost = false; |
| 8416 | } |
| 8417 | |
| 8418 | t_state.redirect_info.redirect_in_process = true; |
| 8419 | |
| 8420 | // set the passed in location url and parse it |
| 8421 | URL redirectUrl; |
| 8422 | redirectUrl.create(nullptr); |
| 8423 | |
| 8424 | redirectUrl.parse(arg_redirect_url, arg_redirect_len); |
| 8425 | { |
| 8426 | int _scheme_len = -1; |
| 8427 | int _host_len = -1; |
| 8428 | if (redirectUrl.scheme_get(&_scheme_len) == nullptr && redirectUrl.host_get(&_host_len) != nullptr && |
| 8429 | arg_redirect_url[0] != '/') { |
| 8430 | // RFC7230 § 5.5 |
| 8431 | // The redirect URL lacked a scheme and so it is a relative URL. |
| 8432 | // The redirect URL did not begin with a slash, so we parsed some or all |
| 8433 | // of the relative URI path as the host. |
| 8434 | // Prepend a slash and parse again. |
nothing calls this directly
no test coverage detected