Commit aabee2f2 authored by Dustin L. Howett's avatar Dustin L. Howett
Browse files

cmd: add logging for redirect requests

parent 85c0e299
......@@ -6,6 +6,9 @@ goget_only = true
# (leave blank to reject all non-go-get requests)
redirect = "https://www.example.org"
# log redirects (NCSA-like)
log = true
[autocert]
# for autocert servers, [admin] will be the
# e-mail address of record for Let's Encrypt
......
......@@ -41,6 +41,7 @@ type Config struct {
Redirect string
Servers []Server `toml:"server"`
Metrics Metrics
Log bool
Autocert struct {
Admin string
Cache string
......@@ -134,6 +135,14 @@ func main() {
var packageHandler http.Handler = http.HandlerFunc(handlePackageGet)
rootHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if conf.GoGetOnly && r.URL.Query().Get("go-get") != "1" {
if conf.Log {
ua := r.Header.Get("User-Agent")
if ua == "" {
ua = "-"
}
log.Printf("%s - - \"%s %s %s\" 301 - \"%s\"", r.RemoteAddr, r.Method, r.URL.Path, r.Proto, ua)
}
n, err := redirectUrl.Parse(r.URL.Path)
if err != nil {
log.Print(err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment