This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 1ae3a3699c6924cc47628b65c40c1d679e45e98d
Author: Leif Hedstrom <[email protected]>
AuthorDate: Tue Sep 10 15:28:39 2024 -0700

    Make the error handle deal with remap redirects (#11567)
    
    (cherry picked from commit fb8f54ead5dfc86b4b96f4e899a130e981e2e9cd)
---
 include/cripts/Error.hpp | 26 ++++++++++++++++++++------
 src/cripts/Error.cc      | 10 ++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/include/cripts/Error.hpp b/include/cripts/Error.hpp
index c86499f738..d1aefea9a4 100644
--- a/include/cripts/Error.hpp
+++ b/include/cripts/Error.hpp
@@ -71,12 +71,12 @@ public:
     Status(const self_type &)         = delete;
     void operator=(const self_type &) = delete;
 
-    static void _set(cripts::Context *context, TSHttpStatus _status);
+    static void _set(cripts::Context *context, TSHttpStatus status);
 
     static void
-    _set(cripts::Context *context, int _status)
+    _set(cripts::Context *context, int status)
     {
-      _set(context, static_cast<TSHttpStatus>(_status));
+      _set(context, static_cast<TSHttpStatus>(status));
     }
 
     static TSHttpStatus _get(cripts::Context *context);
@@ -110,9 +110,22 @@ public:
   }
 
   void
-  Fail()
+  Fail(bool redirect = false)
   {
-    _failed = true;
+    _failed   = true;
+    _redirect = redirect;
+  }
+
+  void
+  Redirect()
+  {
+    _redirect = true;
+  }
+
+  [[nodiscard]] bool
+  Redirected() const
+  {
+    return _redirect;
   }
 
   // Check if we have an error, and set appropriate exit codes etc.
@@ -121,7 +134,8 @@ public:
 private:
   Reason _reason;
   Status _status;
-  bool   _failed = false;
+  bool   _failed   = false;
+  bool   _redirect = false;
 };
 
 } // namespace cripts
diff --git a/src/cripts/Error.cc b/src/cripts/Error.cc
index cfd4db12ac..b1076d6f82 100644
--- a/src/cripts/Error.cc
+++ b/src/cripts/Error.cc
@@ -30,6 +30,10 @@ Error::Execute(cripts::Context *context)
     // ToDo: So we can't set the reason phrase here, because ATS doesn't have 
that
     // as a transaction API, only on the response header...
   }
+
+  if (Redirected()) {
+    context->rri->redirect = 1;
+  }
 }
 
 // These are static, to be used with the set() wrapper define
@@ -45,6 +49,12 @@ Error::Status::_set(cripts::Context *context, TSHttpStatus 
status)
 {
   context->state.error.Fail();
   context->state.error._status._setter(status);
+
+  if (context->state.error.Redirected() || status == 
TS_HTTP_STATUS_MOVED_PERMANENTLY ||
+      status == TS_HTTP_STATUS_MOVED_TEMPORARILY || status == 
TS_HTTP_STATUS_TEMPORARY_REDIRECT ||
+      status == TS_HTTP_STATUS_PERMANENT_REDIRECT) {
+    context->state.error.Redirect();
+  }
 }
 
 TSHttpStatus

Reply via email to