From e65c8f9385bb698d1b0baf2171a7b5390888c25e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 26 Dec 2024 12:29:31 +0300 Subject: [PATCH 01/16] Raise copyright years --- auth.go | 2 +- cfg.go | 2 +- cmd/godlighty/main.go | 2 +- dirlist.go | 2 +- doc/index.texi | 2 +- handler.go | 2 +- media.go | 2 +- meta4/parse.go | 2 +- meta4/scheme.go | 2 +- mtime.go | 2 +- orig.go | 2 +- rc/cgi.go | 2 +- rc/redirect.go | 2 +- rw.go | 2 +- tls.go | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/auth.go b/auth.go index fb2fbfa..02bf16d 100644 --- a/auth.go +++ b/auth.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/cfg.go b/cfg.go index 110e0e3..4ccdc7e 100644 --- a/cfg.go +++ b/cfg.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index 9f09407..8bbadea 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/dirlist.go b/dirlist.go index d0bfc7b..621fb88 100644 --- a/dirlist.go +++ b/dirlist.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/doc/index.texi b/doc/index.texi index f6a05b8..65cbe8d 100644 --- a/doc/index.texi +++ b/doc/index.texi @@ -2,7 +2,7 @@ @settitle godlighty @copying -Copyright @copyright{} 2021-2024 @email{stargrave@@stargrave.org, Sergey Matveev} +Copyright @copyright{} 2021-2025 @email{stargrave@@stargrave.org, Sergey Matveev} @end copying @node Top diff --git a/handler.go b/handler.go index 3060f97..19a5c64 100644 --- a/handler.go +++ b/handler.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/media.go b/media.go index 9409c8b..ef6ebae 100644 --- a/media.go +++ b/media.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/meta4/parse.go b/meta4/parse.go index bd9ef36..e747e3f 100644 --- a/meta4/parse.go +++ b/meta4/parse.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/meta4/scheme.go b/meta4/scheme.go index d664546..5d862fc 100644 --- a/meta4/scheme.go +++ b/meta4/scheme.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/mtime.go b/mtime.go index 35afa48..1b971d8 100644 --- a/mtime.go +++ b/mtime.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/orig.go b/orig.go index 879a8eb..9e4ca70 100644 --- a/orig.go +++ b/orig.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/rc/cgi.go b/rc/cgi.go index 64c63c6..1e4ad40 100644 --- a/rc/cgi.go +++ b/rc/cgi.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/rc/redirect.go b/rc/redirect.go index f98439e..f160b2a 100644 --- a/rc/redirect.go +++ b/rc/redirect.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/rw.go b/rw.go index 4191e1c..f27cc15 100644 --- a/rw.go +++ b/rw.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/tls.go b/tls.go index b79edd7..346eaeb 100644 --- a/tls.go +++ b/tls.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2024 Sergey Matveev +// Copyright (C) 2021-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -- 2.52.0 From 5798b954ef3cf9f8ca810610253fc160c4ece1f0 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 12 Feb 2025 14:51:18 +0300 Subject: [PATCH 02/16] Use Go 1.24 --- auth.go | 2 +- cmd/godlighty/main.go | 2 +- go.mod | 2 +- handler.go | 4 ++-- orig.go | 12 +++++------- rc/mime.go | 2 +- tls.go | 15 +++------------ 7 files changed, 14 insertions(+), 25 deletions(-) diff --git a/auth.go b/auth.go index 02bf16d..fdb565b 100644 --- a/auth.go +++ b/auth.go @@ -38,7 +38,7 @@ func performAuth(w http.ResponseWriter, r *http.Request, cfg *AuthCfg) (string, if err != nil { return username, err } - for _, line := range strings.Split(string(data), "\n") { + for line := range strings.SplitSeq(string(data), "\n") { if len(line) == 0 || line[0] == '#' { continue } diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index 8bbadea..5ca0380 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -76,7 +76,7 @@ func main() { } } else { gids := []int{} - for _, g := range strings.Split(*doSetGIDs, ",") { + for g := range strings.SplitSeq(*doSetGIDs, ",") { var gid int gid, err = strconv.Atoi(g) if err != nil { diff --git a/go.mod b/go.mod index 5eefacf..cacbfd5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.stargrave.org/godlighty -go 1.21.5 +go 1.24 require ( github.com/davecgh/go-spew v1.1.1 diff --git a/handler.go b/handler.go index 19a5c64..4ac2b04 100644 --- a/handler.go +++ b/handler.go @@ -46,10 +46,10 @@ const ( var ( gzPool = sync.Pool{ - New: func() interface{} { return gzip.NewWriter(io.Discard) }, + New: func() any { return gzip.NewWriter(io.Discard) }, } zstdPool = sync.Pool{ - New: func() interface{} { + New: func() any { w, err := zstd.NewWriter( io.Discard, zstd.WithEncoderLevel(zstd.SpeedDefault), diff --git a/orig.go b/orig.go index 9e4ca70..d3e6d7d 100644 --- a/orig.go +++ b/orig.go @@ -17,18 +17,16 @@ package godlighty -import "strings" +import ( + "slices" + "strings" +) func containsDotDot(v string) bool { if !strings.Contains(v, "..") { return false } - for _, ent := range strings.FieldsFunc(v, isSlashRune) { - if ent == ".." { - return true - } - } - return false + return slices.Contains(strings.FieldsFunc(v, isSlashRune), "..") } func isSlashRune(r rune) bool { return r == '/' || r == '\\' } diff --git a/rc/mime.go b/rc/mime.go index 75f3cf7..6cb2efd 100644 --- a/rc/mime.go +++ b/rc/mime.go @@ -25,7 +25,7 @@ func parseMIME(p string) []MIMEEntry { panic(err) } entries := make([]MIMEEntry, 0) - for _, line := range strings.Split(string(tsv), "\n") { + for line := range strings.SplitSeq(string(tsv), "\n") { if len(line) == 0 || line[0] == '#' { continue } diff --git a/tls.go b/tls.go index 346eaeb..7ccc8f7 100644 --- a/tls.go +++ b/tls.go @@ -23,6 +23,7 @@ import ( "fmt" "log" "os" + "slices" ) var ( @@ -39,24 +40,14 @@ var ( ) func CHIHasTLS13(chi *tls.ClientHelloInfo) bool { - for _, v := range chi.SupportedVersions { - if v == tls.VersionTLS13 { - return true - } - } - return false + return slices.Contains(chi.SupportedVersions, tls.VersionTLS13) } func CHIHasEdDSA(chi *tls.ClientHelloInfo) bool { if !CHIHasTLS13(chi) { return false } - for _, ss := range chi.SignatureSchemes { - if ss == tls.Ed25519 { - return true - } - } - return false + return slices.Contains(chi.SignatureSchemes, tls.Ed25519) } func GetCertificate(chi *tls.ClientHelloInfo) (*tls.Certificate, error) { -- 2.52.0 From 146caf62212167835819d447f161939715b5b1b5 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 12 Feb 2025 14:52:36 +0300 Subject: [PATCH 03/16] Update dependant libraries --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index cacbfd5..47e0e7c 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.24 require ( github.com/davecgh/go-spew v1.1.1 github.com/dustin/go-humanize v1.0.1 - github.com/klauspost/compress v1.17.7 - golang.org/x/net v0.19.0 + github.com/klauspost/compress v1.17.11 + golang.org/x/net v0.35.0 ) diff --git a/go.sum b/go.sum index 8693e67..d7bb762 100644 --- a/go.sum +++ b/go.sum @@ -2,7 +2,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= -- 2.52.0 From cd3a63d240fd9e0045a0571da4b6229d5db9f53d Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 20 Feb 2025 15:06:03 +0300 Subject: [PATCH 04/16] More portable zstd instead of bsdiff --- doc/index.texi | 3 ++- make-update | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/doc/index.texi b/doc/index.texi index 65cbe8d..b0b51ab 100644 --- a/doc/index.texi +++ b/doc/index.texi @@ -62,7 +62,8 @@ Can drop (UID, GID, groups) privileges. Basically all configuration is done directly inside source code. You have to recompile it every time configuration changes. Is it a problem? I doubt, because Go is very fast. But it produces huge statically linked -executables, you say! Use @command{bsdiff}/@command{bspatch}! +executables, you say! Use either @command{bsdiff}/@command{bspatch} or +@command{zstd --patch-from}! It is created exclusively to drive my own websites, but if you are interested, then @code{git clone git://git.stargrave.org/godlighty.git} it. diff --git a/make-update b/make-update index 325444f..7d56c11 100755 --- a/make-update +++ b/make-update @@ -10,26 +10,26 @@ mkdir -p updates mv $w updates/$w.old exit } -bsdiff updates/$w.old $w updates/$w.bsdiff +zstd -19 --patch-from updates/$w.old -o updates/$w.patch.zst $w mv updates/$w.old updates/$w.older mv $w updates/$w.old -cat > updates/$w-update.sh <updates/$w-update.sh <> updates/$w-update.sh +b64encode updates/$w.patch.zst >updates/$w-update.sh chmod +x updates/$w-update.sh -- 2.52.0 From 30b4664aba2dc67ab1f6dfde60d3d92ca3e8c505 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 26 Feb 2025 15:57:05 +0300 Subject: [PATCH 05/16] zstd warns about files overwriting --- make-update | 1 + 1 file changed, 1 insertion(+) diff --git a/make-update b/make-update index 7d56c11..618fd61 100755 --- a/make-update +++ b/make-update @@ -10,6 +10,7 @@ mkdir -p updates mv $w updates/$w.old exit } +rm -f updates/$w.patch.zst zstd -19 --patch-from updates/$w.old -o updates/$w.patch.zst $w mv updates/$w.old updates/$w.older mv $w updates/$w.old -- 2.52.0 From ee4a911412332b9a4b9205940fafe8604793866c Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 12 Apr 2025 19:48:26 +0300 Subject: [PATCH 06/16] Proper escaping of dirlists with colons --- dirlist.go | 3 ++- dirlist.tmpl | 2 +- godlighty.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dirlist.go b/dirlist.go index 621fb88..bdf47eb 100644 --- a/dirlist.go +++ b/dirlist.go @@ -22,6 +22,7 @@ import ( "os" "path" "sort" + "strings" "time" "github.com/dustin/go-humanize" @@ -105,7 +106,7 @@ func dirList( Files []DirListFile }{ Root: root, - Dir: dir, + Dir: strings.TrimRight(dir, "/"), Readme: readme, Files: files, }) diff --git a/dirlist.tmpl b/dirlist.tmpl index 8fb266f..b63ccd4 100644 --- a/dirlist.tmpl +++ b/dirlist.tmpl @@ -13,7 +13,7 @@  NameMtimeSizeType {{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}} {{.Idx}} - + {{- .Name}}{{if .IsDir}}/{{end}} {{.ModTime}} {{.Size}} diff --git a/godlighty.go b/godlighty.go index ee2ff75..c81b102 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.7.0" +const Version = "godlighty/0.8.0" var BindAddr string -- 2.52.0 From 0698bbdc233f4fcc2cf1aad14deff71cc2234a08 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 22 Apr 2025 23:43:46 +0300 Subject: [PATCH 07/16] Yet another proper escaping --- dirlist.go | 9 ++++----- dirlist.tmpl | 2 +- godlighty.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dirlist.go b/dirlist.go index bdf47eb..b0b2918 100644 --- a/dirlist.go +++ b/dirlist.go @@ -22,7 +22,6 @@ import ( "os" "path" "sort" - "strings" "time" "github.com/dustin/go-humanize" @@ -51,7 +50,7 @@ func (a ByName) Less(i, j int) bool { } type DirListFile struct { - Name string + Name template.URL Size string Type string ModTime string @@ -75,14 +74,14 @@ func dirList( } file := DirListFile{ Idx: i, - Name: fi.Name(), + Name: template.URL(fi.Name()), Size: humanize.IBytes(uint64(fi.Size())), ModTime: fi.ModTime().UTC().Truncate(time.Second).Format(MTimeFmt), } if fi.IsDir() { file.IsDir = true } else { - file.Type = mediaType(file.Name, cfg.MIMEs) + file.Type = mediaType(fi.Name(), cfg.MIMEs) } if (entry.Type() & fs.ModeSymlink) > 0 { file.Symlink, _ = os.Readlink(path.Join(pth, fi.Name())) @@ -106,7 +105,7 @@ func dirList( Files []DirListFile }{ Root: root, - Dir: strings.TrimRight(dir, "/"), + Dir: dir, Readme: readme, Files: files, }) diff --git a/dirlist.tmpl b/dirlist.tmpl index b63ccd4..8fb266f 100644 --- a/dirlist.tmpl +++ b/dirlist.tmpl @@ -13,7 +13,7 @@  NameMtimeSizeType {{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}} {{.Idx}} - + {{- .Name}}{{if .IsDir}}/{{end}} {{.ModTime}} {{.Size}} diff --git a/godlighty.go b/godlighty.go index c81b102..895b10c 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.8.0" +const Version = "godlighty/0.9.0" var BindAddr string -- 2.52.0 From eebd6b1d10cd0c8ec6daf6d41244525f029a0894 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 8 Oct 2025 11:40:02 +0300 Subject: [PATCH 08/16] Ability to disable HTTP/2 --- cmd/godlighty/main.go | 10 ++++++++++ godlighty.go | 2 +- tls.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index 5ca0380..6cbba08 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -46,6 +46,7 @@ var ( func main() { bind := flag.String("bind", "[::]:80", "Address to bind and listen on") doTLS := flag.Bool("tls", false, "Enable TLS") + noH2 := flag.Bool("no-h2", false, "Disable HTTP/2") doSetUID := flag.Int("setuid", 0, "Set that UID after binding the socket") doSetGID := flag.Int("setgid", 0, "Set that GID after binding the socket") doSetGIDs := flag.String("setgids", "", "Comma-separated GIDs to set") @@ -108,6 +109,15 @@ func main() { Handler: godlighty.MainHandler, ReadHeaderTimeout: RWTimeout, IdleTimeout: time.Minute, + Protocols: &http.Protocols{}, + } + srv.Protocols.SetHTTP1(true) + if *noH2 { + godlighty.NextProtos = []string{"http/1.1"} + } else { + godlighty.NextProtos = []string{"h2", "http/1.1"} + srv.Protocols.SetHTTP2(true) + srv.Protocols.SetUnencryptedHTTP2(true) } go func() { <-shutdown diff --git a/godlighty.go b/godlighty.go index 895b10c..834266e 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.9.0" +const Version = "godlighty/0.10.0" var BindAddr string diff --git a/tls.go b/tls.go index 7ccc8f7..e42b06f 100644 --- a/tls.go +++ b/tls.go @@ -27,7 +27,7 @@ import ( ) var ( - NextProtos = []string{"h2", "http/1.1"} + NextProtos []string HostToECDSACertificate map[string]*tls.Certificate HostECDSAClientAuth map[string]*x509.CertPool -- 2.52.0 From 8c59f851a69e0e9036ecac4ad8cd244b82e8a291 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 8 Oct 2025 13:00:48 +0300 Subject: [PATCH 09/16] Update dependant libraries --- go.mod | 6 +++--- go.sum | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 47e0e7c..ae38fda 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module go.stargrave.org/godlighty -go 1.24 +go 1.25 require ( github.com/davecgh/go-spew v1.1.1 github.com/dustin/go-humanize v1.0.1 - github.com/klauspost/compress v1.17.11 - golang.org/x/net v0.35.0 + github.com/klauspost/compress v1.18.0 + golang.org/x/net v0.45.0 ) diff --git a/go.sum b/go.sum index d7bb762..51e4a7c 100644 --- a/go.sum +++ b/go.sum @@ -2,7 +2,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= -github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= -golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM= +golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= -- 2.52.0 From 84895f0486900dc8a31762a22d11ae24a5dcf3cc Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 8 Oct 2025 13:01:42 +0300 Subject: [PATCH 10/16] +build lines are not required anymore --- cmd/godlighty/info.go | 1 - cmd/godlighty/info_linux.go | 1 - tls_gost.go | 1 - tls_nogost.go | 1 - 4 files changed, 4 deletions(-) diff --git a/cmd/godlighty/info.go b/cmd/godlighty/info.go index fc3e8c1..76b9aa5 100644 --- a/cmd/godlighty/info.go +++ b/cmd/godlighty/info.go @@ -1,5 +1,4 @@ //go:build !linux -// +build !linux package main diff --git a/cmd/godlighty/info_linux.go b/cmd/godlighty/info_linux.go index 386d6b3..68c0e9e 100644 --- a/cmd/godlighty/info_linux.go +++ b/cmd/godlighty/info_linux.go @@ -1,5 +1,4 @@ //go:build linux -// +build linux package main diff --git a/tls_gost.go b/tls_gost.go index 0acb778..b1f2222 100644 --- a/tls_gost.go +++ b/tls_gost.go @@ -1,5 +1,4 @@ //go:build !nogostls13 -// +build !nogostls13 package godlighty diff --git a/tls_nogost.go b/tls_nogost.go index 571d980..d753ba0 100644 --- a/tls_nogost.go +++ b/tls_nogost.go @@ -1,5 +1,4 @@ //go:build nogostls13 -// +build nogostls13 package godlighty -- 2.52.0 From 5b00e2e294adef67f8f1aea5170745f5e5249f3e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 25 Dec 2025 19:44:29 +0300 Subject: [PATCH 11/16] default target with extension is more reliable --- default.do => default.cmd.do | 6 +++--- make-update | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) rename default.do => default.cmd.do (67%) diff --git a/default.do b/default.cmd.do similarity index 67% rename from default.do rename to default.cmd.do index 82e6356..cf6e228 100644 --- a/default.do +++ b/default.cmd.do @@ -1,8 +1,8 @@ -[ -d rc/"$1".cfg ] || { - echo No rc/"$1".cfg found >&2 +[ -d rc/"$2".cfg ] || { + echo No rc/"$2".cfg found >&2 exit 1 } rm -f rc/cfg -ln -s $1.cfg rc/cfg +ln -s $2.cfg rc/cfg redo-ifchange cmd/godlighty/*.go *.go go.* rc/*.go rc/mime/* rc/cfg/*.go ${GO:-go} build -o $3 $GO_FLAGS -ldflags=-s ./cmd/godlighty diff --git a/make-update b/make-update index 618fd61..c74b815 100755 --- a/make-update +++ b/make-update @@ -3,17 +3,17 @@ w=$1 [ -n "$w" ] [ -d rc/$w.cfg ] -redo $w +redo $w.cmd mkdir -p updates [ -s updates/$w.old ] || { echo This is first run - mv $w updates/$w.old + mv $w.cmd updates/$w.old exit } rm -f updates/$w.patch.zst -zstd -19 --patch-from updates/$w.old -o updates/$w.patch.zst $w +zstd -19 --patch-from updates/$w.old -o updates/$w.patch.zst $w.cmd mv updates/$w.old updates/$w.older -mv $w updates/$w.old +mv $w.cmd updates/$w.old cat >updates/$w-update.sh < Date: Tue, 30 Dec 2025 13:45:50 +0300 Subject: [PATCH 12/16] Raise copyright years --- auth.go | 2 +- cfg.go | 2 +- cmd/godlighty/main.go | 2 +- dirlist.go | 2 +- doc/index.texi | 2 +- handler.go | 2 +- media.go | 2 +- meta4/parse.go | 2 +- meta4/scheme.go | 2 +- mtime.go | 2 +- orig.go | 2 +- rc/cgi.go | 2 +- rc/redirect.go | 2 +- rw.go | 2 +- tls.go | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/auth.go b/auth.go index fdb565b..e96c944 100644 --- a/auth.go +++ b/auth.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/cfg.go b/cfg.go index 4ccdc7e..eebda40 100644 --- a/cfg.go +++ b/cfg.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index 6cbba08..c65979b 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/dirlist.go b/dirlist.go index b0b2918..62882bd 100644 --- a/dirlist.go +++ b/dirlist.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/doc/index.texi b/doc/index.texi index b0b51ab..e0727fc 100644 --- a/doc/index.texi +++ b/doc/index.texi @@ -2,7 +2,7 @@ @settitle godlighty @copying -Copyright @copyright{} 2021-2025 @email{stargrave@@stargrave.org, Sergey Matveev} +Copyright @copyright{} 2021-2026 @email{stargrave@@stargrave.org, Sergey Matveev} @end copying @node Top diff --git a/handler.go b/handler.go index 4ac2b04..d31857a 100644 --- a/handler.go +++ b/handler.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/media.go b/media.go index ef6ebae..2e15598 100644 --- a/media.go +++ b/media.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/meta4/parse.go b/meta4/parse.go index e747e3f..7a90e46 100644 --- a/meta4/parse.go +++ b/meta4/parse.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/meta4/scheme.go b/meta4/scheme.go index 5d862fc..82ce4a5 100644 --- a/meta4/scheme.go +++ b/meta4/scheme.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/mtime.go b/mtime.go index 1b971d8..38ee5e1 100644 --- a/mtime.go +++ b/mtime.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/orig.go b/orig.go index d3e6d7d..db25bf6 100644 --- a/orig.go +++ b/orig.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/rc/cgi.go b/rc/cgi.go index 1e4ad40..4ee9c99 100644 --- a/rc/cgi.go +++ b/rc/cgi.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/rc/redirect.go b/rc/redirect.go index f160b2a..74ac515 100644 --- a/rc/redirect.go +++ b/rc/redirect.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/rw.go b/rw.go index f27cc15..1d0006f 100644 --- a/rw.go +++ b/rw.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/tls.go b/tls.go index e42b06f..7e7c9fa 100644 --- a/tls.go +++ b/tls.go @@ -1,5 +1,5 @@ // godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -// Copyright (C) 2021-2025 Sergey Matveev +// Copyright (C) 2021-2026 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by -- 2.52.0 From c9fc71de412259c29217ee7559e1720327045b61 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 13 Feb 2026 16:32:21 +0300 Subject: [PATCH 13/16] Add pri/geo attributes to Links --- godlighty.go | 2 +- handler.go | 9 ++++++++- meta4/parse.go | 6 ++---- meta4/scheme.go | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/godlighty.go b/godlighty.go index 834266e..60c1c4b 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.10.0" +const Version = "godlighty/0.11.0" var BindAddr string diff --git a/handler.go b/handler.go index d31857a..43fa36a 100644 --- a/handler.go +++ b/handler.go @@ -268,7 +268,14 @@ IndexLookuped: `>; rel=describedby; type="application/metalink4+xml"`, ) for _, u := range forHTTP.URLs { - w.Header().Add("Link", "<"+u+">; rel=duplicate") + s := "<" + u.URL + ">; rel=duplicate" + if u.Priority != 0 { + s += "; pri=" + strconv.Itoa(int(u.Priority)) + } + if u.Location != "" { + s += "; geo=" + u.Location + } + w.Header().Add("Link", s) } for name, digest := range forHTTP.Hashes { w.Header().Add("Digest", name+"="+base64.StdEncoding.EncodeToString(digest)) diff --git a/meta4/parse.go b/meta4/parse.go index 7a90e46..ca128f1 100644 --- a/meta4/parse.go +++ b/meta4/parse.go @@ -37,7 +37,7 @@ var KnownHashes = map[string]string{ type ForHTTP struct { Hashes map[string][]byte - URLs []string + URLs []URL Torrents []string } @@ -63,9 +63,7 @@ func Parse(fn string, data []byte) (*ForHTTP, error) { } forHTTP.Hashes[name] = digest } - for _, u := range f.URLs { - forHTTP.URLs = append(forHTTP.URLs, u.URL) - } + forHTTP.URLs = f.URLs for _, m := range f.MetaURLs { if m.MediaType == "torrent" { forHTTP.Torrents = append(forHTTP.Torrents, m.URL) diff --git a/meta4/scheme.go b/meta4/scheme.go index 82ce4a5..a082c9b 100644 --- a/meta4/scheme.go +++ b/meta4/scheme.go @@ -44,8 +44,10 @@ type File struct { } type URL struct { - XMLName xml.Name `xml:"url"` - URL string `xml:",chardata"` + XMLName xml.Name `xml:"url"` + Location string `xml:"location,attr"` + Priority uint `xml:"priority,attr"` + URL string `xml:",chardata"` } type Signature struct { -- 2.52.0 From 5421b46e49e63ce9c562166714871120f520f091 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 13 Feb 2026 16:36:09 +0300 Subject: [PATCH 14/16] Convert documentation to SWG --- doc/.swgignore | 2 + doc/Configuration | 119 ++++++++++++++++++++++++++++++++++++++++ doc/Usage | 31 +++++++++++ doc/cfg.texi | 136 ---------------------------------------------- doc/index | 52 ++++++++++++++++++ doc/index.texi | 76 -------------------------- doc/mk-html | 8 +++ doc/usage.texi | 39 ------------- doc/www.do | 13 ----- 9 files changed, 212 insertions(+), 264 deletions(-) create mode 100644 doc/.swgignore create mode 100644 doc/Configuration create mode 100644 doc/Usage delete mode 100644 doc/cfg.texi create mode 100644 doc/index delete mode 100644 doc/index.texi create mode 100755 doc/mk-html delete mode 100644 doc/usage.texi delete mode 100644 doc/www.do diff --git a/doc/.swgignore b/doc/.swgignore new file mode 100644 index 0000000..e90ee87 --- /dev/null +++ b/doc/.swgignore @@ -0,0 +1,2 @@ +^mk-html$ +^godlighty.html/ diff --git a/doc/Configuration b/doc/Configuration new file mode 100644 index 0000000..d2d1b39 --- /dev/null +++ b/doc/Configuration @@ -0,0 +1,119 @@ +Initially godlighty has basic static files handlers (with compression, +HTTP preconditions are enabled of course). In the example below there +are nearly all default functions. Also look for rc/example.cfg. + + Hosts["example.com"] = &godlighty.HostCfg{ + Root: "/www/example.com", + EdDSATLS: &godlighty.TLSCfg{ + Cert: "/path/to/example.com.pem", + Key: "/path/to/example.com.key.pem", + CACert: "/path/to/ca.pem", + }, + DirList: true, + WebDAV: true, + MIMEs: map[string]string{ + ".special": "text/x-special-type", + }, + } + +If your keys and certificates are in single file and you use common CA +certificate, then it is trivial to DRY: + + var ( + Etc = "/whatever" + CACert = path.Join(Etc, "ca.pem") + ) + + func newTLSCfg(host string) *godlighty.TLSCfg { + return &godlighty.TLSCfg{ + Cert: path.Join(Etc, host+".pem"), + Key: path.Join(Etc, host+".pem"), + CACert: CACert, + } + } + +But there are hooks that can do anything more. For example if you want +to run CGI script or make a redirection (FastCGI handler example is in +rc/fcgi.example.cfg): + + HostCfg{ + ..., + Hooks: []godlighty.Hook{ + func(w http.ResponseWriter, r *http.Request) bool { + if r.URL.Path == "/" { + http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently) + return true + } + return false + }, + func(w http.ResponseWriter, r *http.Request) bool { + cgi.Handler{ + Path: "/usr/local/libexec/git-core/git-http-backend", + Dir: "/var/empty", + Env: []string{ + "GIT_PROJECT_ROOT=" + root, + "GIT_HTTP_EXPORT_ALL=", + }, + }.ServeHTTP(w, r) + return true + }, + }, + +You can separate your configuration files and add them through init() call: + + $ ls rc/stargrave.org.cfg + blog.stargrave.org.go + ca.cypherpunks.ru.go + cgi.go + cryptoanarchy.ru.go + git.go + go.go + if.mirror.cypherpunks.ru.go + lists.cypherpunks.ru.go + static.go + tls.go + [...] + + $ cat rc/stargrave.org.cfg/static.go + package rc + + import "path" + + func addStaticCfg(host, root string) { + if !path.IsAbs(root) { + root = path.Join(WWW, root) + } + godlighty.Hosts[host] = &godlighty.HostCfg{ + Root: root, + TLS: newTLSCfg(host), + } + } + + func addStaticListedDir(host, root string) { + addStaticCfg(host, root) + godlighty.Hosts[host].DirList = true + godlighty.Hosts[host].WebDAV = true + } + + func init() { + [...] + addStaticCfg("paster.stargrave.org", "/storage/paster/pastes") + addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org") + addStaticCfg("www.nncpgo.org", "nncpgo.org") + addStaticListedDir("www.mds.cypherpunks.su", "/storage/audiobook/mds") + [...] + } + +There are some pre-existing helpers to deal with: + +rc/cgi.go + CGI scripts. + +rc/redirect.go + Loggable redirects. + +rc/mime.go, rc/mime/* + Predefined Content-Type entries. Each file in rc/mime/* has + tab-separated format: file's extension, media type and optional + "c" mark, meaning that these type can be transparently compressed + on-the-fly. diff --git a/doc/Usage b/doc/Usage new file mode 100644 index 0000000..4664d87 --- /dev/null +++ b/doc/Usage @@ -0,0 +1,31 @@ +All [Configuration] is assumed to be placed in rc/cfg. Probably you want +to deal with multiple server configurations simultaneously. You place +them in corresponding rc/NAME.cfg directories and use redo default +target to create necessary symbolic link of rc/NAME.cfg to rc/cfg and +build executable itself. + +=> http://cr.yp.to/redo.html + + $ redo example.cmd + # will produce example executable with rc/example.cfg configuration + + $ redo fcgi.example.cmd + # will produce fcgi.example executable with rc/fcgi.example.cfg configuration + +But because you will mostly like to create binary patches to quickly +update already existing binaries, then you can use make-update script, +that will store newly created binaries in updates/ directory and make +shell-script with the built-in binary patch and SHA512 checksum checker: + + # First run + $ ./make-update example + $ scp updates/example.old web-server:/path/to/www-server + + $ ./make-update example + $ scp updates/example-update.sh web-server:/tmp + web-server $ /tmp/example-update.sh /path/to/www-server + web-server $ svc -t /var/service/www-server + +contrib/service contains daemontools example run scripts. + +Send SIGINFO (SIGUSR1 on Linux) signal to get current daemon's configuration. diff --git a/doc/cfg.texi b/doc/cfg.texi deleted file mode 100644 index 530502d..0000000 --- a/doc/cfg.texi +++ /dev/null @@ -1,136 +0,0 @@ -@node Configuration -@unnumbered Configuration - -Initially @command{godlighty} has basic static files handlers (with -compression, HTTP preconditions are enabled of course). In the example -below there are nearly all default functions. -Also look for @file{rc/example.cfg}. - -@verbatim -Hosts["example.com"] = &godlighty.HostCfg{ - Root: "/www/example.com", - EdDSATLS: &godlighty.TLSCfg{ - Cert: "/path/to/example.com.pem", - Key: "/path/to/example.com.key.pem", - CACert: "/path/to/ca.pem", - }, - DirList: true, - WebDAV: true, - MIMEs: map[string]string{ - ".special": "text/x-special-type", - }, -} -@end verbatim - -If your keys and certificates are in single file and you use common CA -certificate, then it is trivial to DRY: - -@verbatim -var ( - Etc = "/whatever" - CACert = path.Join(Etc, "ca.pem") -) - -func newTLSCfg(host string) *godlighty.TLSCfg { - return &godlighty.TLSCfg{ - Cert: path.Join(Etc, host+".pem"), - Key: path.Join(Etc, host+".pem"), - CACert: CACert, - } -} -@end verbatim - -But there are hooks that can do anything more. For example if you want -to run CGI script or make a redirection (FastCGI handler example is in -@file{rc/fcgi.example.cfg}): - -@verbatim -HostCfg{ - ..., - Hooks: []godlighty.Hook{ - func(w http.ResponseWriter, r *http.Request) bool { - if r.URL.Path == "/" { - http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently) - return true - } - return false - }, - func(w http.ResponseWriter, r *http.Request) bool { - cgi.Handler{ - Path: "/usr/local/libexec/git-core/git-http-backend", - Dir: "/var/empty", - Env: []string{ - "GIT_PROJECT_ROOT=" + root, - "GIT_HTTP_EXPORT_ALL=", - }, - }.ServeHTTP(w, r) - return true - }, - }, -@end verbatim - -You can separate your configuration files and add them through -@code{init()} call: - -@verbatim -$ ls rc/stargrave.org.cfg -blog.stargrave.org.go -ca.cypherpunks.ru.go -cgi.go -cryptoanarchy.ru.go -git.go -go.go -if.mirror.cypherpunks.ru.go -lists.cypherpunks.ru.go -static.go -tls.go -[...] - -$ cat rc/stargrave.org.cfg/static.go -package rc - -import "path" - -func addStaticCfg(host, root string) { - if !path.IsAbs(root) { - root = path.Join(WWW, root) - } - godlighty.Hosts[host] = &godlighty.HostCfg{ - Root: root, - TLS: newTLSCfg(host), - } -} - -func addStaticListedDir(host, root string) { - addStaticCfg(host, root) - godlighty.Hosts[host].DirList = true - godlighty.Hosts[host].WebDAV = true -} - -func init() { - [...] - addStaticCfg("paster.stargrave.org", "/storage/paster/pastes") - addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org") - addStaticCfg("www.nncpgo.org", "nncpgo.org") - addStaticListedDir("www.mds.cypherpunks.ru", "/storage/audiobook/mds") - [...] -} -@end verbatim - -There are some preexisting helpers to deal with: - -@table @file - -@item rc/cgi.go -CGI scripts. - -@item rc/redirect.go -Loggable redirects. - -@item rc/mime.go, rc/mime/* -Predefined @code{Content-Type} entries. Each file in @file{rc/mime/*} -has tab-separated format: file's extension, media type and optional -@code{c} mark, meaning that these type can be transparently compressed -on-the-fly. - -@end table diff --git a/doc/index b/doc/index new file mode 100644 index 0000000..bd5c450 --- /dev/null +++ b/doc/index @@ -0,0 +1,52 @@ +godlighty is free software highly-customizable HTTP, HTTP/2, HTTPS +server written on pure Go. + +Why yet another web-server? Because all others suck even for my simple +ordinary needs: they use hateful OpenSSL, lack documentation, has +complex configuration format, lack some features, hard to extend with. + +* Pretty minimalistic pure-Go web-server with few number of + dependencies, producing single statically linked executable. + Maximal reuse of native libraries capabilities. + +* Modern, reliable, secure and fast TLS 1.3 implementation with + ChaCha20-Poly1305, hybrid PQ/T KEM, session resumption and SNI + (depends on Go version you are using). + +* If built with gostls13, then GOST TLS 1.3 cryptography will be fully + supported, with ability to use GOST-based X.509 certificates if client + announces its knowledge of GOST algorithms (with the fallback to + ordinary ECDSA/EdDSA ones). + => http://www.gostls13.cypherpunks.su/ gostls13 + => http://www.gost.cypherpunks.su/ GOST + +* HTTP/1.1, HTTP/2 (optionally, only when negotiated during ALPN) and + keepalives support. Graceful shutdowns. + +* gzip and Zstandard compression on-the-fly. + +* Range, ETag (based on file/directory's mtime), Last-Modified and + corresponding precondition handlers are fully used. + +* Auto-generated directory listings and read-only WebDAV support. + +* Per-domain HTTP basic authorization and TLS client authentication. + +* If corresponding .meta4 files are found, it is parsed and additional + Links with Digests headers are generated automatically, based on that + Metalink file. + => http://www.metalinker.org/ Metalink + +* Friendly to daemontools. Can drop (UID, GID, groups) privileges. + => http://cr.yp.to/daemontools.html + +Basically all configuration is done directly inside source code. You +have to recompile it every time configuration changes. Is it a problem? +I doubt, because Go is very fast. But it produces huge statically linked +executables, you say! Use either bsdiff/bspatch or zstd --patch-from! + +It is created exclusively to drive my own websites, but if you are +interested, then git clone git://git.stargrave.org/godlighty.git + +[Configuration] +[Usage] diff --git a/doc/index.texi b/doc/index.texi deleted file mode 100644 index e0727fc..0000000 --- a/doc/index.texi +++ /dev/null @@ -1,76 +0,0 @@ -\input texinfo -@settitle godlighty - -@copying -Copyright @copyright{} 2021-2026 @email{stargrave@@stargrave.org, Sergey Matveev} -@end copying - -@node Top -@top godlighty - -@command{godlighty} is -@url{https://www.gnu.org/philosophy/free-sw.html, free software} -highly-customizable HTTP, HTTP/2, HTTPS server written on pure Go. - -Why yet another web-server? Because all others suck even for my simple -ordinary needs: they use hateful OpenSSL, lack documentation, has -complex configuration format, lack some features, hard to extend with. - -@itemize - -@item Rather minimalistic pure-Go web-server with few number of -dependencies, producing single statically linked executable. Maximal -reuse of native libraries capabilities. - -@item Modern, reliable, secure and fast TLS 1.3 implementation with -ChaCha20-Poly1305, session resumption and SNI. - -@item If built with @url{http://www.gostls13.cypherpunks.su/, gostls13}, -then @url{http://www.gost.cypherpunks.su/, GOST} TLS 1.3 cryptography -will be fully supported, with ability to use GOST-based X.509 -certificates if client announces its knowledge of GOST algorithms (with -the fallback to ordinary ECDSA/EdDSA ones). - -@item HTTP/1.1, @url{https://en.wikipedia.org/wiki/HTTP%2F2, HTTP/2} -(only when negotiated during ALPN) and keepalives support. Graceful -shutdowns. - - -@item @url{https://en.wikipedia.org/wiki/Gzip, gzip} and -@url{https://facebook.github.io/zstd/, Zstandard} -compression on-the-fly. - -@item @code{Range}, @code{ETag} (based on file/directory's -@code{ctime}), @code{Last-Modified} and corresponding precondition -handlers are fully used. - -@item Auto-generated directory listings and -read-only @url{https://en.wikipedia.org/wiki/WebDAV, WebDAV} support. - -@item Per-domain HTTP basic authorization and TLS client authentication. - -@item If corresponding @file{.meta4} files are found, it is parsed and -additional @code{Link}s with @code{Digest}s headers are generated -automatically, based on that @url{http://www.metalinker.org/, Metalink} -file. - -@item Very friendly to @url{http://cr.yp.to/daemontools.html, daemontools}. -Can drop (UID, GID, groups) privileges. - -@end itemize - -Basically all configuration is done directly inside source code. You -have to recompile it every time configuration changes. Is it a problem? -I doubt, because Go is very fast. But it produces huge statically linked -executables, you say! Use either @command{bsdiff}/@command{bspatch} or -@command{zstd --patch-from}! - -It is created exclusively to drive my own websites, but if you are -interested, then @code{git clone git://git.stargrave.org/godlighty.git} it. - -@insertcopying - -@include cfg.texi -@include usage.texi - -@bye diff --git a/doc/mk-html b/doc/mk-html new file mode 100755 index 0000000..5c85436 --- /dev/null +++ b/doc/mk-html @@ -0,0 +1,8 @@ +#!/bin/sh + +html=godlighty.html +rm -f $html/*.html +SWG_DO_SRC=0 SWG_DO_BACKS=0 swg htmls $html +perl -i -npe 's#^.*$#<title>godlighty#' $html/index.html +find $html -type d -exec chmod 755 {} + +find $html -type f -exec chmod 644 {} + diff --git a/doc/usage.texi b/doc/usage.texi deleted file mode 100644 index 3eb93bd..0000000 --- a/doc/usage.texi +++ /dev/null @@ -1,39 +0,0 @@ -@node Usage -@unnumbered Usage - -All @ref{Configuration, configuration} is assumed to be placed in -@file{rc/cfg}. Probably you want to deal with multiple server -configurations simultaneously. You place them in corresponding -@file{rc/NAME.cfg} directories and use @url{http://cr.yp.to/redo.html, -redo} default target to create necessary symbolic link of -@file{rc/NAME.cfg} to @file{rc/cfg} and build executable itself. - -@example -$ redo example -# will produce example executable with rc/example.cfg configuration - -$ redo fcgi.example -# will produce fcgi.example executable with rc/fcgi.example.cfg configuration -@end example - -But because you will mostly like to create binary patches to quickly -update already existing binaries, then you can use @file{make-update.sh} -script, that will store newly created binaries in @file{updates/} -directory and make shell-script with the built-in binary patch and -SHA512 checksum checker: - -@example -# First run -$ ./make-update example -$ scp updates/example.old web-server:/path/to/www-server - -$ ./make-update example -$ scp updates/example-update.sh web-server:/tmp -web-server $ /tmp/example-update.sh /path/to/www-server -web-server $ svc -t /var/service/www-server -@end example - -@file{contrib/service} contains @command{daemontools} example run scripts. - -Send @code{SIGINFO} (@code{SIGUSR1} on Linux) signal to get current -daemon's configuration. diff --git a/doc/www.do b/doc/www.do deleted file mode 100644 index 9f0d6c2..0000000 --- a/doc/www.do +++ /dev/null @@ -1,13 +0,0 @@ -redo-ifchange *.texi -html=godlighty.html -rm -f $html/*.html -${MAKEINFO:=makeinfo} --html \ - --set-customization-variable NO_CSS=1 \ - --set-customization-variable SECTION_NAME_IN_TITLE=1 \ - --set-customization-variable TREE_TRANSFORMATIONS=complete_tree_nodes_menus \ - --set-customization-variable FORMAT_MENU=menu \ - --set-customization-variable DATE_IN_HEADER=1 \ - --set-customization-variable ASCII_PUNCTUATION=1 \ - --output $html index.texi -find $html -type d -exec chmod 755 {} + -find $html -type f -exec chmod 644 {} + -- 2.52.0 From 2acf63a57149d0fc85edf10e164c2f59dfed8d2c Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 2 Mar 2026 17:45:03 +0300 Subject: [PATCH 15/16] -no-gzip --- cmd/godlighty/main.go | 4 ++++ handler.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index c65979b..40f9e37 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -47,6 +47,7 @@ func main() { bind := flag.String("bind", "[::]:80", "Address to bind and listen on") doTLS := flag.Bool("tls", false, "Enable TLS") noH2 := flag.Bool("no-h2", false, "Disable HTTP/2") + noGzip := flag.Bool("no-gzip", false, "Disable gzip compression support") doSetUID := flag.Int("setuid", 0, "Set that UID after binding the socket") doSetGID := flag.Int("setgid", 0, "Set that GID after binding the socket") doSetGIDs := flag.String("setgids", "", "Comma-separated GIDs to set") @@ -104,6 +105,9 @@ func main() { } }() + if *noGzip { + godlighty.NoGzip = true + } godlighty.BindAddr = *bind srv := http.Server{ Handler: godlighty.MainHandler, diff --git a/handler.go b/handler.go index 43fa36a..e31a034 100644 --- a/handler.go +++ b/handler.go @@ -45,6 +45,8 @@ const ( ) var ( + NoGzip bool + gzPool = sync.Pool{ New: func() any { return gzip.NewWriter(io.Discard) }, } @@ -308,7 +310,7 @@ SkipMeta4: zstdW.Reset(bufCompressed) defer zstdW.Close() wc = &gzipResponseWriter{ResponseWriter: w, Writer: zstdW} - } else if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { + } else if !NoGzip && strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { w.Header().Set("Content-Encoding", "gzip") gz = gzPool.Get().(*gzip.Writer) defer gzPool.Put(gz) -- 2.52.0 From 15d4cc8ed48655b57d85009a74d9d23a5cd10489 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 3 Mar 2026 14:30:23 +0300 Subject: [PATCH 16/16] Normalise IPv6 hostnames --- godlighty.go | 2 +- handler.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/godlighty.go b/godlighty.go index 60c1c4b..8233c4b 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.11.0" +const Version = "godlighty/0.12.0" var BindAddr string diff --git a/handler.go b/handler.go index e31a034..abdd27b 100644 --- a/handler.go +++ b/handler.go @@ -361,5 +361,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { host = r.Host } + if len(host) > 2 && host[0] == '[' && host[len(host)-1] == ']' { + if ip6 := net.ParseIP(host[1 : len(host)-1]); ip6 != nil { + host = "[" + ip6.String() + "]" + } + } h.Handle(w, r, host, Hosts[host]) } -- 2.52.0