Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Also http Status Code 3xx #1

Open
tranmh opened this issue Aug 6, 2020 · 0 comments
Open

Accept Also http Status Code 3xx #1

tranmh opened this issue Aug 6, 2020 · 0 comments

Comments

@tranmh
Copy link

tranmh commented Aug 6, 2020

Hi,

I am kindly asking you to change the watchdog-tomcat.go code, so that it also accepts http status code 3xx instead of 200 only.

My change is as diff is:

diff --git a/watchdog-tomcat.go b/watchdog-tomcat.go
index d1b8612..cf792d3 100644
--- a/watchdog-tomcat.go
+++ b/watchdog-tomcat.go
@@ -72,13 +72,20 @@ func runWatchedApp(application string) (pid int, err error) {
 func healthCheck(check_url string, timeout time.Duration) (bool, error) {
     var netClient = &http.Client{
         Timeout: time.Second * timeout,
+        CheckRedirect: func(req *http.Request, via []*http.Request) error {
+            return http.ErrUseLastResponse
+        },
     }
     resp, err := netClient.Get(check_url)
     if err != nil {
         return false, err
     }
-    if resp.StatusCode != 200 {
-        return false, errors.New("health check status is not 200")
+    if resp.StatusCode == 200  {
+        return true, nil
+    } else if resp.StatusCode >= 300 && resp.StatusCode < 400 {
+        return true, nil
+    } else {
+        return false, errors.New("health check status is not 200 or 3xx")
     }
     defer resp.Body.Close()
     return true, nil
@@ -186,4 +193,4 @@ func main() {
         }
     }(check_url)
     wg.Wait()
}

I followed this post for making the change.
https://stackoverflow.com/questions/23297520/how-can-i-make-the-go-http-client-not-follow-redirects-automatically

It would be nice, if you can put my change to branch master.

Thx.

tranmh referenced this issue in tranmh/systemd-watchdog-tomcat Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant