| 503 | } |
| 504 | |
| 505 | void |
| 506 | EditRedirectResponse(TSHttpTxn txnp, const std::string &location, TSHttpStatus status, TSMBuffer bufp, TSMLoc hdr_loc) |
| 507 | { |
| 508 | // Set new location. |
| 509 | TSMLoc field_loc; |
| 510 | static std::string header("Location"); |
| 511 | if (TS_SUCCESS == TSMimeHdrFieldCreateNamed(bufp, hdr_loc, header.c_str(), header.size(), &field_loc)) { |
| 512 | if (TS_SUCCESS == TSMimeHdrFieldValueStringSet(bufp, hdr_loc, field_loc, -1, location.c_str(), location.size())) { |
| 513 | Dbg(pi_dbg_ctl, " Adding header %s", header.c_str()); |
| 514 | TSMimeHdrFieldAppend(bufp, hdr_loc, field_loc); |
| 515 | } |
| 516 | const char *reason = TSHttpHdrReasonLookup(status); |
| 517 | size_t len = strlen(reason); |
| 518 | TSHttpHdrReasonSet(bufp, hdr_loc, reason, len); |
| 519 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 520 | } |
| 521 | |
| 522 | // Set the body. |
| 523 | static std::string msg = "<HTML>\n<HEAD>\n<TITLE>Document Has Moved</TITLE>\n</HEAD>\n" |
| 524 | "<BODY BGCOLOR=\"white\" FGCOLOR=\"black\">\n" |
| 525 | "<H1>Document Has Moved</H1>\n<HR>\n<FONT FACE=\"Helvetica,Arial\"><B>\n" |
| 526 | "Description: The document you requested has moved to a new location." |
| 527 | " The new location is \"" + |
| 528 | location + "\".\n</B></FONT>\n<HR>\n</BODY>\n"; |
| 529 | TSHttpTxnErrorBodySet(txnp, TSstrdup(msg.c_str()), msg.length(), TSstrdup("text/html")); |
| 530 | } |
| 531 | |
| 532 | bool |
| 533 | OperatorSetRedirect::exec(const Resources &res) const |
no test coverage detected