From 844431329b9348e7b454843c63b9990611aee85f Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Wed, 27 Feb 2019 10:55:34 -0800 Subject: [PATCH 1/6] Updated to using Go 1.12.0. --- Dockerfile | 6 +++--- Dockerfile.all | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ad757fd..66235c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ ################################################################################ ## GO BUILDER ################################################################################ -FROM golang:1.11.5 as builder +FROM golang:1.12.0 as builder -ENV VERSION 1.6.1 +ENV VERSION 1.6.2 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -31,5 +31,5 @@ LABEL life.apets.vendor="Halverneus" \ life.apets.url="https://github.com/halverneus/static-file-server" \ life.apets.name="Static File Server" \ life.apets.description="A tiny static file server" \ - life.apets.version="v1.6.1" \ + life.apets.version="v1.6.2" \ life.apets.schema-version="1.0" diff --git a/Dockerfile.all b/Dockerfile.all index 5558b12..609fce3 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -1,6 +1,6 @@ -FROM golang:1.11.5 as builder +FROM golang:1.12.0 as builder -ENV VERSION 1.6.1 +ENV VERSION 1.6.2 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -21,5 +21,5 @@ LABEL life.apets.vendor="Halverneus" \ life.apets.url="https://github.com/halverneus/static-file-server" \ life.apets.name="Static File Server" \ life.apets.description="A tiny static file server" \ - life.apets.version="v1.6.1" \ + life.apets.version="v1.6.2" \ life.apets.schema-version="1.0" From 451f3150d52440fedd84380be341dc66f0ca3877 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Tue, 26 Mar 2019 21:16:06 -0700 Subject: [PATCH 2/6] Updated to using Go 1.12.1. --- Dockerfile | 6 +++--- Dockerfile.all | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 66235c8..31425ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ ################################################################################ ## GO BUILDER ################################################################################ -FROM golang:1.12.0 as builder +FROM golang:1.12.1 as builder -ENV VERSION 1.6.2 +ENV VERSION 1.6.3 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -31,5 +31,5 @@ LABEL life.apets.vendor="Halverneus" \ life.apets.url="https://github.com/halverneus/static-file-server" \ life.apets.name="Static File Server" \ life.apets.description="A tiny static file server" \ - life.apets.version="v1.6.2" \ + life.apets.version="v1.6.3" \ life.apets.schema-version="1.0" diff --git a/Dockerfile.all b/Dockerfile.all index 609fce3..1bf2a33 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -1,6 +1,6 @@ -FROM golang:1.12.0 as builder +FROM golang:1.12.1 as builder -ENV VERSION 1.6.2 +ENV VERSION 1.6.3 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -21,5 +21,5 @@ LABEL life.apets.vendor="Halverneus" \ life.apets.url="https://github.com/halverneus/static-file-server" \ life.apets.name="Static File Server" \ life.apets.description="A tiny static file server" \ - life.apets.version="v1.6.2" \ + life.apets.version="v1.6.3" \ life.apets.schema-version="1.0" From 7793fde0caed32c8d058cc3883cff3850ac777e5 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Mon, 8 Apr 2019 12:23:29 -0700 Subject: [PATCH 3/6] Fixed remote address logging and added appropriate unit tests. --- handle/handle.go | 32 +++++++++++++++++++++++--------- handle/handle_test.go | 25 ++++++++++++++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/handle/handle.go b/handle/handle.go index 0dc42c2..babedd3 100644 --- a/handle/handle.go +++ b/handle/handle.go @@ -49,15 +49,29 @@ func WithReferrers(serveFile FileServerFunc, referrers []string) FileServerFunc // to serving the requested file. func WithLogging(serveFile FileServerFunc) FileServerFunc { return func(w http.ResponseWriter, r *http.Request, name string) { - log.Printf( - "REQ from '%s': %s %s %s%s -> %s\n", - r.Referer(), - r.Method, - r.Proto, - r.Host, - r.URL.Path, - name, - ) + referer := r.Referer() + if 0 == len(referer) { + log.Printf( + "REQ from '%s': %s %s %s%s -> %s\n", + r.RemoteAddr, + r.Method, + r.Proto, + r.Host, + r.URL.Path, + name, + ) + } else { + log.Printf( + "REQ from '%s' (REFERER: '%s'): %s %s %s%s -> %s\n", + r.RemoteAddr, + referer, + r.Method, + r.Proto, + r.Host, + r.URL.Path, + name, + ) + } serveFile(w, r, name) } } diff --git a/handle/handle_test.go b/handle/handle_test.go index 0fdded9..11dd6d7 100644 --- a/handle/handle_test.go +++ b/handle/handle_test.go @@ -152,19 +152,29 @@ func TestWithReferrers(t *testing.T) { } func TestBasicWithAndWithoutLogging(t *testing.T) { + referer := "http://localhost" + noReferer := "" testCases := []struct { name string path string code int + refer string contents string }{ - {"Good base dir", "", ok, tmpIndex}, - {"Good base index", tmpIndexName, redirect, nothing}, - {"Good base file", tmpFileName, ok, tmpFile}, - {"Bad base file", tmpBadName, missing, notFound}, - {"Good subdir dir", subDir, ok, tmpSubIndex}, - {"Good subdir index", tmpSubIndexName, redirect, nothing}, - {"Good subdir file", tmpSubFileName, ok, tmpSubFile}, + {"Good base dir", "", ok, referer, tmpIndex}, + {"Good base index", tmpIndexName, redirect, referer, nothing}, + {"Good base file", tmpFileName, ok, referer, tmpFile}, + {"Bad base file", tmpBadName, missing, referer, notFound}, + {"Good subdir dir", subDir, ok, referer, tmpSubIndex}, + {"Good subdir index", tmpSubIndexName, redirect, referer, nothing}, + {"Good subdir file", tmpSubFileName, ok, referer, tmpSubFile}, + {"Good base dir", "", ok, noReferer, tmpIndex}, + {"Good base index", tmpIndexName, redirect, noReferer, nothing}, + {"Good base file", tmpFileName, ok, noReferer, tmpFile}, + {"Bad base file", tmpBadName, missing, noReferer, notFound}, + {"Good subdir dir", subDir, ok, noReferer, tmpSubIndex}, + {"Good subdir index", tmpSubIndexName, redirect, noReferer, nothing}, + {"Good subdir file", tmpSubFileName, ok, noReferer, tmpSubFile}, } for _, serveFile := range serveFileFuncs { @@ -173,6 +183,7 @@ func TestBasicWithAndWithoutLogging(t *testing.T) { t.Run(tc.name, func(t *testing.T) { fullpath := "http://localhost/" + tc.path req := httptest.NewRequest("GET", fullpath, nil) + req.Header.Add("Referer", tc.refer) w := httptest.NewRecorder() handler(w, req) From 6c5615ba44a190a2896ab1ee4353389f6d70751d Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Thu, 11 Apr 2019 10:42:48 -0700 Subject: [PATCH 4/6] Updated compiler to Go 1.12.3. --- Dockerfile | 2 +- Dockerfile.all | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31425ff..31106db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ################################################################################ ## GO BUILDER ################################################################################ -FROM golang:1.12.1 as builder +FROM golang:1.12.3 as builder ENV VERSION 1.6.3 ENV BUILD_DIR /build diff --git a/Dockerfile.all b/Dockerfile.all index 1bf2a33..d8a17de 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -1,4 +1,4 @@ -FROM golang:1.12.1 as builder +FROM golang:1.12.3 as builder ENV VERSION 1.6.3 ENV BUILD_DIR /build From 222f24f51866a05ea1e22db9764b7d4a08e096ee Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Thu, 11 Apr 2019 10:46:43 -0700 Subject: [PATCH 5/6] Updated documentation to specify which debug messages are printed to stdout and stderr. --- README.md | 3 ++- cli/help/help.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9bc7f39..1fad068 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ Default values are shown with the associated environment variable. ```bash # Enable debugging for troubleshooting. If set to 'true' this prints extra -# information during execution. +# information during execution. IMPORTANT NOTE: The configuration summary is +# printed to stdout while logs generated during execution are printed to stderr. DEBUG=false # Optional Hostname for binding. Leave black to accept any incoming HTTP request diff --git a/cli/help/help.go b/cli/help/help.go index 55032c2..6f8a3fa 100644 --- a/cli/help/help.go +++ b/cli/help/help.go @@ -35,8 +35,9 @@ DEPENDENCIES ENVIRONMENT VARIABLES DEBUG When set to 'true' enables additional logging, including the - configuration used and an access log for each request. Default value is - 'false'. + configuration used and an access log for each request. IMPORTANT NOTE: + The configuration summary is printed to stdout while logs generated + during execution are printed to stderr. Default value is 'false'. FOLDER The path to the folder containing the contents to be served over HTTP(s). If not supplied, defaults to '/web' (for Docker reasons). From c21cd4ba7dcd328cb1248f2632673bf6cca8b856 Mon Sep 17 00:00:00 2001 From: Jeromy Streets Date: Thu, 11 Apr 2019 10:47:46 -0700 Subject: [PATCH 6/6] Updated revision number to 1.6.4. --- Dockerfile | 4 ++-- Dockerfile.all | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31106db..5213fef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ################################################################################ FROM golang:1.12.3 as builder -ENV VERSION 1.6.3 +ENV VERSION 1.6.4 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -31,5 +31,5 @@ LABEL life.apets.vendor="Halverneus" \ life.apets.url="https://github.com/halverneus/static-file-server" \ life.apets.name="Static File Server" \ life.apets.description="A tiny static file server" \ - life.apets.version="v1.6.3" \ + life.apets.version="v1.6.4" \ life.apets.schema-version="1.0" diff --git a/Dockerfile.all b/Dockerfile.all index d8a17de..642b167 100644 --- a/Dockerfile.all +++ b/Dockerfile.all @@ -1,6 +1,6 @@ FROM golang:1.12.3 as builder -ENV VERSION 1.6.3 +ENV VERSION 1.6.4 ENV BUILD_DIR /build RUN mkdir -p ${BUILD_DIR} @@ -21,5 +21,5 @@ LABEL life.apets.vendor="Halverneus" \ life.apets.url="https://github.com/halverneus/static-file-server" \ life.apets.name="Static File Server" \ life.apets.description="A tiny static file server" \ - life.apets.version="v1.6.3" \ + life.apets.version="v1.6.4" \ life.apets.schema-version="1.0"