From 9856ac7fafc358e2e558a7f9efdd90bc7a9f09c0 Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Tue, 20 Feb 2018 13:12:44 +0300 Subject: [PATCH] Logging proxy requests in verbose mode (fixes #173) --- docs/log-files.adoc | 1 + proxy.go | 7 +++++-- proxy_test.go | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/log-files.adoc b/docs/log-files.adoc index 804f3a5..cfa66d5 100644 --- a/docs/log-files.adoc +++ b/docs/log-files.adoc @@ -42,6 +42,7 @@ The following statuses are available: | INVALID_VNC_REQUEST_URL | VNC request URL do not contain enough information to determine upstream host | INVALID_VIDEO_REQUEST_URL | Video request URL do not contain enough information to determine upstream host | INVALID_URL | Session ID does not contain information about host where it was created +| PROXYING | Proxying Selenium request (shown in verbose mode only) | PROXYING_TO_VNC | Starting to proxy VNC traffic | PROXYING_VIDEO | Starting to proxy video from upstream host | QUOTA_INFO_REQUESTED | Quota information request arrived diff --git a/proxy.go b/proxy.go index 6352ffe..5c2e053 100644 --- a/proxy.go +++ b/proxy.go @@ -333,8 +333,11 @@ func proxy(r *http.Request) { r.URL.Host = h.net() r.URL.Path = proxyPath fragments := strings.Split(proxyPath, "/") - if r.Method == "DELETE" && len(fragments) == sessPart+1 { - sess := fragments[sessPart] + sess := fragments[sessPart] + if verbose { + log.Printf("[%d] [-] [PROXYING] [-] [%s] [-] [%s] [%s] [-] [%s]\n", id, remote, h.net(), sess, proxyPath) + } + if r.Method == http.MethodDelete && len(fragments) == sessPart+1 { log.Printf("[%d] [-] [SESSION_DELETED] [-] [%s] [-] [%s] [%s] [-] [-]\n", id, remote, h.net(), sess) } return diff --git a/proxy_test.go b/proxy_test.go index 2d5e7e0..d31c2cc 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -75,6 +75,7 @@ func init() { srv = httptest.NewServer(mux()) listen = hostport(srv.URL) gitRevision = "test-revision" + verbose = true } func gridrouter(p string) string {