summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-05-01 07:56:25 -0600
committertjpcc <tjp@ctrl-c.club>2023-05-01 07:56:25 -0600
commit9a2da81b11ad0064cca24ce7974827d032309369 (patch)
tree4313224dc089208423e78bffc3ec50833e35bcea /contrib
parent21e2758145d100d74013060f7090d84679cae683 (diff)
name change gus -> sliderule
Diffstat (limited to 'contrib')
-rw-r--r--contrib/cgi/cgi.go6
-rw-r--r--contrib/cgi/cgi_test.go10
-rw-r--r--contrib/cgi/gemini.go8
-rw-r--r--contrib/cgi/gopher.go8
-rw-r--r--contrib/cgi/spartan.go8
-rw-r--r--contrib/fs/dir.go8
-rw-r--r--contrib/fs/dir_test.go14
-rw-r--r--contrib/fs/file.go4
-rw-r--r--contrib/fs/file_test.go10
-rw-r--r--contrib/fs/gemini.go18
-rw-r--r--contrib/fs/gopher.go18
-rw-r--r--contrib/fs/spartan.go18
-rw-r--r--contrib/sharedhost/replacement.go12
-rw-r--r--contrib/sharedhost/replacement_test.go10
-rw-r--r--contrib/tlsauth/approver_test.go2
-rw-r--r--contrib/tlsauth/auth.go12
-rw-r--r--contrib/tlsauth/auth_test.go38
-rw-r--r--contrib/tlsauth/gemini.go20
-rw-r--r--contrib/tlsauth/gemini_test.go22
19 files changed, 123 insertions, 123 deletions
diff --git a/contrib/cgi/cgi.go b/contrib/cgi/cgi.go
index e57f2d0..6c727aa 100644
--- a/contrib/cgi/cgi.go
+++ b/contrib/cgi/cgi.go
@@ -13,7 +13,7 @@ import (
"os/exec"
"strings"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
// ResolveCGI finds a CGI program corresponding to a request path.
@@ -91,7 +91,7 @@ func isNotExistError(err error) bool {
// RunCGI runs a specific program as a CGI script.
func RunCGI(
ctx context.Context,
- request *gus.Request,
+ request *sr.Request,
executable string,
pathInfo string,
) (io.Reader, int, error) {
@@ -130,7 +130,7 @@ func RunCGI(
func prepareCGIEnv(
ctx context.Context,
- request *gus.Request,
+ request *sr.Request,
scriptName string,
pathInfo string,
) []string {
diff --git a/contrib/cgi/cgi_test.go b/contrib/cgi/cgi_test.go
index 5c1ca33..ff2c45d 100644
--- a/contrib/cgi/cgi_test.go
+++ b/contrib/cgi/cgi_test.go
@@ -12,9 +12,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/contrib/cgi"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/contrib/cgi"
+ "tildegit.org/tjp/sliderule/gemini"
)
func TestCGIDirectory(t *testing.T) {
@@ -30,7 +30,7 @@ func TestCGIDirectory(t *testing.T) {
tests := []struct {
requestPath string
- responseCode gus.Status
+ responseCode sr.Status
responseBody string
}{
{
@@ -69,7 +69,7 @@ func TestCGIDirectory(t *testing.T) {
code, err := strconv.Atoi(string(response[:2]))
if assert.Nil(t, err) {
- assert.Equal(t, test.responseCode, gus.Status(code))
+ assert.Equal(t, test.responseCode, sr.Status(code))
}
_, body, found := strings.Cut(string(response), "\r\n")
diff --git a/contrib/cgi/gemini.go b/contrib/cgi/gemini.go
index 1587037..d245c8e 100644
--- a/contrib/cgi/gemini.go
+++ b/contrib/cgi/gemini.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/gemini"
)
// GeminiCGIDirectory runs any executable files relative to a root directory on the file system.
@@ -15,9 +15,9 @@ import (
// a request for /foo/bar/baz can also run an executable found at /foo or /foo/bar. In
// such a case the PATH_INFO environment variable will include the remaining portion of
// the URI path.
-func GeminiCGIDirectory(pathRoot, fsRoot string) gus.Handler {
+func GeminiCGIDirectory(pathRoot, fsRoot string) sr.Handler {
fsRoot = strings.TrimRight(fsRoot, "/")
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, pathRoot) {
return nil
}
diff --git a/contrib/cgi/gopher.go b/contrib/cgi/gopher.go
index 4378eb7..290adfa 100644
--- a/contrib/cgi/gopher.go
+++ b/contrib/cgi/gopher.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/gopher"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/gopher"
)
// GopherCGIDirectory runs any executable files relative to a root directory on the file system.
@@ -15,9 +15,9 @@ import (
// a request for /foo/bar/baz can also run an executable found at /foo or /foo/bar. In
// such a case the PATH_INFO environment variable will include the remaining portion of
// the URI path.
-func GopherCGIDirectory(pathRoot, fsRoot string) gus.Handler {
+func GopherCGIDirectory(pathRoot, fsRoot string) sr.Handler {
fsRoot = strings.TrimRight(fsRoot, "/")
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, pathRoot) {
return nil
}
diff --git a/contrib/cgi/spartan.go b/contrib/cgi/spartan.go
index 01ebb19..6994466 100644
--- a/contrib/cgi/spartan.go
+++ b/contrib/cgi/spartan.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/spartan"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/spartan"
)
// SpartanCGIDirectory runs executable files relative to a root directory in the file system.
@@ -14,9 +14,9 @@ import (
// It will also find any run any executable _part way_ through the path, so for example a
// request for /foo/bar/baz can also run an executable found at /foo or /foo/bar. In such
// a case the PATH_INFO environment variable will include the remaining portion of the URI.
-func SpartanCGIDirectory(pathRoot, fsRoot string) gus.Handler {
+func SpartanCGIDirectory(pathRoot, fsRoot string) sr.Handler {
fsRoot = strings.TrimRight(fsRoot, "/")
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, pathRoot) {
return nil
}
diff --git a/contrib/fs/dir.go b/contrib/fs/dir.go
index 5659804..bb2d933 100644
--- a/contrib/fs/dir.go
+++ b/contrib/fs/dir.go
@@ -8,7 +8,7 @@ import (
"strings"
"text/template"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
// ResolveDirectory opens the directory corresponding to a request path.
@@ -16,7 +16,7 @@ import (
// The string is the full path to the directory. If the returned ReadDirFile
// is not nil, it will be open and must be closed by the caller.
func ResolveDirectory(
- request *gus.Request,
+ request *sr.Request,
fileSystem fs.FS,
) (string, fs.ReadDirFile, error) {
path := strings.Trim(request.Path, "/")
@@ -102,7 +102,7 @@ func RenderDirectoryListing(
path string,
dir fs.ReadDirFile,
template *template.Template,
- server gus.Server,
+ server sr.Server,
) (io.Reader, error) {
buf := &bytes.Buffer{}
@@ -118,7 +118,7 @@ func RenderDirectoryListing(
return buf, nil
}
-func dirlistNamespace(path string, dirFile fs.ReadDirFile, server gus.Server) (map[string]any, error) {
+func dirlistNamespace(path string, dirFile fs.ReadDirFile, server sr.Server) (map[string]any, error) {
entries, err := dirFile.ReadDir(0)
if err != nil {
return nil, err
diff --git a/contrib/fs/dir_test.go b/contrib/fs/dir_test.go
index 9c6770d..6b6f60f 100644
--- a/contrib/fs/dir_test.go
+++ b/contrib/fs/dir_test.go
@@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/contrib/fs"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/contrib/fs"
+ "tildegit.org/tjp/sliderule/gemini"
)
func TestDirectoryDefault(t *testing.T) {
@@ -20,7 +20,7 @@ func TestDirectoryDefault(t *testing.T) {
tests := []struct {
url string
- status gus.Status
+ status sr.Status
meta string
body string
}{
@@ -46,7 +46,7 @@ func TestDirectoryDefault(t *testing.T) {
u, err := url.Parse(test.url)
require.Nil(t, err)
- request := &gus.Request{URL: u}
+ request := &sr.Request{URL: u}
response := handler.Handle(context.Background(), request)
if response == nil {
@@ -73,7 +73,7 @@ func TestDirectoryListing(t *testing.T) {
tests := []struct {
url string
- status gus.Status
+ status sr.Status
meta string
body string
}{
@@ -107,7 +107,7 @@ func TestDirectoryListing(t *testing.T) {
u, err := url.Parse(test.url)
require.Nil(t, err)
- request := &gus.Request{URL: u}
+ request := &sr.Request{URL: u}
response := handler.Handle(context.Background(), request)
if response == nil {
diff --git a/contrib/fs/file.go b/contrib/fs/file.go
index a1293af..591c1bd 100644
--- a/contrib/fs/file.go
+++ b/contrib/fs/file.go
@@ -5,7 +5,7 @@ import (
"mime"
"strings"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
// ResolveFile finds a file from a filesystem based on a request path.
@@ -13,7 +13,7 @@ import (
// It only returns a non-nil file if a file is found - not a directory.
// If there is any other sort of filesystem access error, it will be
// returned.
-func ResolveFile(request *gus.Request, fileSystem fs.FS) (string, fs.File, error) {
+func ResolveFile(request *sr.Request, fileSystem fs.FS) (string, fs.File, error) {
filepath := strings.TrimPrefix(request.Path, "/")
file, err := fileSystem.Open(filepath)
if isNotFound(err) {
diff --git a/contrib/fs/file_test.go b/contrib/fs/file_test.go
index 3949b83..55e2a09 100644
--- a/contrib/fs/file_test.go
+++ b/contrib/fs/file_test.go
@@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/contrib/fs"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/contrib/fs"
+ "tildegit.org/tjp/sliderule/gemini"
)
func TestFileHandler(t *testing.T) {
@@ -20,7 +20,7 @@ func TestFileHandler(t *testing.T) {
tests := []struct {
url string
- status gus.Status
+ status sr.Status
meta string
body string
}{
@@ -57,7 +57,7 @@ func TestFileHandler(t *testing.T) {
u, err := url.Parse(test.url)
require.Nil(t, err)
- request := &gus.Request{URL: u}
+ request := &sr.Request{URL: u}
response := handler.Handle(context.Background(), request)
if response == nil {
diff --git a/contrib/fs/gemini.go b/contrib/fs/gemini.go
index 21ca32d..fbf8d08 100644
--- a/contrib/fs/gemini.go
+++ b/contrib/fs/gemini.go
@@ -6,15 +6,15 @@ import (
"strings"
"text/template"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/gemini"
)
// GeminiFileHandler builds a handler which serves up files from a file system.
//
// It only serves responses for paths which do not correspond to directories on disk.
-func GeminiFileHandler(fileSystem fs.FS) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GeminiFileHandler(fileSystem fs.FS) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
filepath, file, err := ResolveFile(request, fileSystem)
if err != nil {
return gemini.Failure(err)
@@ -41,8 +41,8 @@ func GeminiFileHandler(fileSystem fs.FS) gus.Handler {
//
// It requires that files from the provided fs.FS implement fs.ReadDirFile. If they
// don't, it will produce nil responses for any directory paths.
-func GeminiDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GeminiDirectoryDefault(fileSystem fs.FS, filenames ...string) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
dirpath, dir, response := handleDirGemini(request, fileSystem)
if response != nil {
return response
@@ -77,8 +77,8 @@ func GeminiDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
//
// The template may be nil, in which case DefaultGeminiDirectoryList is used instead. The
// template is then processed with RenderDirectoryListing.
-func GeminiDirectoryListing(fileSystem fs.FS, template *template.Template) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GeminiDirectoryListing(fileSystem fs.FS, template *template.Template) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
dirpath, dir, response := handleDirGemini(request, fileSystem)
if response != nil {
return response
@@ -109,7 +109,7 @@ var DefaultGeminiDirectoryList = template.Must(template.New("gemini_dirlist").Pa
=> ../
`[1:]))
-func handleDirGemini(request *gus.Request, fileSystem fs.FS) (string, fs.ReadDirFile, *gus.Response) {
+func handleDirGemini(request *sr.Request, fileSystem fs.FS) (string, fs.ReadDirFile, *sr.Response) {
path, dir, err := ResolveDirectory(request, fileSystem)
if err != nil {
return "", nil, gemini.Failure(err)
diff --git a/contrib/fs/gopher.go b/contrib/fs/gopher.go
index f63785c..e7e4ab9 100644
--- a/contrib/fs/gopher.go
+++ b/contrib/fs/gopher.go
@@ -8,15 +8,15 @@ import (
"strings"
"text/template"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/gopher"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/gopher"
)
// GopherFileHandler builds a handler which serves up files from a file system.
//
// It only serves responses for paths which correspond to files, not directories.
-func GopherFileHandler(fileSystem fs.FS) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GopherFileHandler(fileSystem fs.FS) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
filepath, file, err := ResolveFile(request, fileSystem)
if err != nil {
return gopher.Error(err).Response()
@@ -39,8 +39,8 @@ func GopherFileHandler(fileSystem fs.FS) gus.Handler {
//
// It requires that files from the provided fs.FS implement fs.ReadDirFile. If
// they don't, it will produce nil responses for all directory paths.
-func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
dirpath, dir, err := ResolveDirectory(request, fileSystem)
if err != nil {
return gopher.Error(err).Response()
@@ -71,8 +71,8 @@ func GopherDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
//
// A template may be nil, in which case DefaultGopherDirectoryList is used instead. The
// template is then processed with RenderDirectoryListing.
-func GopherDirectoryListing(fileSystem fs.FS, tpl *template.Template) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GopherDirectoryListing(fileSystem fs.FS, tpl *template.Template) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
dirpath, dir, err := ResolveDirectory(request, fileSystem)
if err != nil {
return gopher.Error(err).Response()
@@ -130,7 +130,7 @@ i {{ $hostname }} {{ $port }}
)
// GuessGopherItemType attempts to find the best gopher item type for a file based on its name.
-func GuessGopherItemType(filepath string) gus.Status {
+func GuessGopherItemType(filepath string) sr.Status {
ext := path.Ext(filepath)
switch ext {
case "txt", "gmi":
diff --git a/contrib/fs/spartan.go b/contrib/fs/spartan.go
index 550f549..70943ee 100644
--- a/contrib/fs/spartan.go
+++ b/contrib/fs/spartan.go
@@ -6,15 +6,15 @@ import (
"strings"
"text/template"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/spartan"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/spartan"
)
// SpartanFileHandler builds a handler which serves up files from a filesystem.
//
// It only serves responses for paths which do not correspond to directories on disk.
-func SpartanFileHandler(fileSystem fs.FS) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func SpartanFileHandler(fileSystem fs.FS) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
filepath, file, err := ResolveFile(request, fileSystem)
if err != nil {
return spartan.ClientError(err)
@@ -41,8 +41,8 @@ func SpartanFileHandler(fileSystem fs.FS) gus.Handler {
//
// It requires that files from the provided fs.FS implement fs.ReadDirFile. If they
// don't, it will produce nil responses for any directory paths.
-func SpartanDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func SpartanDirectoryDefault(fileSystem fs.FS, filenames ...string) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
dirpath, dir, response := handleDirSpartan(request, fileSystem)
if response != nil {
return response
@@ -77,8 +77,8 @@ func SpartanDirectoryDefault(fileSystem fs.FS, filenames ...string) gus.Handler
//
// The tmeplate may be nil, in which cause DefaultSpartanDirectoryList is used instead. The
// template is then processed with RenderDirectoryListing.
-func SpartanDirectoryListing(filesystem fs.FS, template *template.Template) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func SpartanDirectoryListing(filesystem fs.FS, template *template.Template) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
dirpath, dir, response := handleDirSpartan(request, filesystem)
if response != nil {
return response
@@ -103,7 +103,7 @@ func SpartanDirectoryListing(filesystem fs.FS, template *template.Template) gus.
// DefaultSpartanDirectoryList is a template which renders a reasonable gemtext dir listing.
var DefaultSpartanDirectoryList = DefaultGeminiDirectoryList
-func handleDirSpartan(request *gus.Request, filesystem fs.FS) (string, fs.ReadDirFile, *gus.Response) {
+func handleDirSpartan(request *sr.Request, filesystem fs.FS) (string, fs.ReadDirFile, *sr.Response) {
path, dir, err := ResolveDirectory(request, filesystem)
if err != nil {
return "", nil, spartan.ServerError(err)
diff --git a/contrib/sharedhost/replacement.go b/contrib/sharedhost/replacement.go
index 9267530..9dc3a1e 100644
--- a/contrib/sharedhost/replacement.go
+++ b/contrib/sharedhost/replacement.go
@@ -5,7 +5,7 @@ import (
"crypto/tls"
"net/url"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
// ReplaceTilde builds a middleware which substitutes a leading '~' in the request path.
@@ -17,9 +17,9 @@ import (
// Typically the replacement should end with a "/", so that the ~ ends up mapping to a
// particular directory on the filesystem. For instance with a replacement string of
// "users/", "domain.com/~jim/index.gmi" maps to "domain.com/users/jim/index.gmi".
-func ReplaceTilde(replacement string) gus.Middleware {
- return func(inner gus.Handler) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func ReplaceTilde(replacement string) sr.Middleware {
+ return func(inner sr.Handler) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
if len(request.Path) > 1 && request.Path[0] == '/' && request.Path[1] == '~' {
request = cloneRequest(request)
request.Path = "/" + replacement + request.Path[2:]
@@ -30,8 +30,8 @@ func ReplaceTilde(replacement string) gus.Middleware {
}
}
-func cloneRequest(start *gus.Request) *gus.Request {
- next := &gus.Request{}
+func cloneRequest(start *sr.Request) *sr.Request {
+ next := &sr.Request{}
*next = *start
next.URL = &url.URL{}
diff --git a/contrib/sharedhost/replacement_test.go b/contrib/sharedhost/replacement_test.go
index 67c3754..9fa9161 100644
--- a/contrib/sharedhost/replacement_test.go
+++ b/contrib/sharedhost/replacement_test.go
@@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/assert"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/contrib/sharedhost"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/contrib/sharedhost"
)
func TestReplaceTilde(t *testing.T) {
@@ -42,10 +42,10 @@ func TestReplaceTilde(t *testing.T) {
originalPath := u.Path
replacer := sharedhost.ReplaceTilde(test.replacement)
- request := &gus.Request{URL: u}
- handler := replacer(gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ request := &sr.Request{URL: u}
+ handler := replacer(sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
assert.Equal(t, test.replacedPath, request.Path)
- return &gus.Response{}
+ return &sr.Response{}
}))
handler.Handle(context.Background(), request)
diff --git a/contrib/tlsauth/approver_test.go b/contrib/tlsauth/approver_test.go
index a2af838..d2f4f07 100644
--- a/contrib/tlsauth/approver_test.go
+++ b/contrib/tlsauth/approver_test.go
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
- "tildegit.org/tjp/gus/contrib/tlsauth"
+ "tildegit.org/tjp/sliderule/contrib/tlsauth"
)
func TestRequireSpecificIdentity(t *testing.T) {
diff --git a/contrib/tlsauth/auth.go b/contrib/tlsauth/auth.go
index 38ec3a3..439d297 100644
--- a/contrib/tlsauth/auth.go
+++ b/contrib/tlsauth/auth.go
@@ -4,11 +4,11 @@ import (
"context"
"crypto/x509"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
// Identity returns the client certificate for the request or nil if there is none.
-func Identity(request *gus.Request) *x509.Certificate {
+func Identity(request *sr.Request) *x509.Certificate {
if request.TLSState == nil || len(request.TLSState.PeerCertificates) == 0 {
return nil
}
@@ -19,8 +19,8 @@ func Identity(request *gus.Request) *x509.Certificate {
//
// The check requires both that there is a client certificate associated with the
// request and that it passes the provided approver.
-func RequiredAuth(approve Approver) func(context.Context, *gus.Request) bool {
- return func(_ context.Context, request *gus.Request) bool {
+func RequiredAuth(approve Approver) func(context.Context, *sr.Request) bool {
+ return func(_ context.Context, request *sr.Request) bool {
identity := Identity(request)
if identity == nil {
return false
@@ -34,8 +34,8 @@ func RequiredAuth(approve Approver) func(context.Context, *gus.Request) bool {
//
// The check allows through any request with no client certificate, but if
// there is one present then it requires that it pass the provided approver.
-func OptionalAuth(approve Approver) func(context.Context, *gus.Request) bool {
- return func(_ context.Context, request *gus.Request) bool {
+func OptionalAuth(approve Approver) func(context.Context, *sr.Request) bool {
+ return func(_ context.Context, request *sr.Request) bool {
identity := Identity(request)
if identity == nil {
return true
diff --git a/contrib/tlsauth/auth_test.go b/contrib/tlsauth/auth_test.go
index 3cbc106..2a95e1c 100644
--- a/contrib/tlsauth/auth_test.go
+++ b/contrib/tlsauth/auth_test.go
@@ -12,9 +12,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/contrib/tlsauth"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/contrib/tlsauth"
+ "tildegit.org/tjp/sliderule/gemini"
)
func TestIdentify(t *testing.T) {
@@ -24,7 +24,7 @@ func TestIdentify(t *testing.T) {
server, client, clientCert := setup(t,
"testdata/server.crt", "testdata/server.key",
"testdata/client1.crt", "testdata/client1.key",
- gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
invoked = true
ident := tlsauth.Identity(request)
@@ -51,20 +51,20 @@ func TestRequiredAuth(t *testing.T) {
invoked1 := false
invoked2 := false
- handler1 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler1 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
invoked1 = true
return gemini.Success("", &bytes.Buffer{})
})
- handler2 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler2 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
invoked2 = true
return gemini.Success("", &bytes.Buffer{})
})
- authMiddleware := gus.Filter(tlsauth.RequiredAuth(tlsauth.Allow), nil)
+ authMiddleware := sr.Filter(tlsauth.RequiredAuth(tlsauth.Allow), nil)
- handler1 = gus.Filter(
- func(_ context.Context, req *gus.Request) bool {
+ handler1 = sr.Filter(
+ func(_ context.Context, req *sr.Request) bool {
return strings.HasPrefix(req.Path, "/one")
},
nil,
@@ -74,7 +74,7 @@ func TestRequiredAuth(t *testing.T) {
server, client, _ := setup(t,
"testdata/server.crt", "testdata/server.key",
"testdata/client1.crt", "testdata/client1.key",
- gus.FallthroughHandler(handler1, handler2),
+ sr.FallthroughHandler(handler1, handler2),
)
go func() {
@@ -94,7 +94,7 @@ func TestOptionalAuth(t *testing.T) {
invoked1 := false
invoked2 := false
- handler1 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler1 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, "/one") {
return nil
}
@@ -103,13 +103,13 @@ func TestOptionalAuth(t *testing.T) {
return gemini.Success("", &bytes.Buffer{})
})
- handler2 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler2 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
invoked2 = true
return gemini.Success("", &bytes.Buffer{})
})
- mw := gus.Filter(tlsauth.OptionalAuth(tlsauth.Reject), nil)
- handler := gus.FallthroughHandler(mw(handler1), mw(handler2))
+ mw := sr.Filter(tlsauth.OptionalAuth(tlsauth.Reject), nil)
+ handler := sr.FallthroughHandler(mw(handler1), mw(handler2))
server, client, _ := setup(t,
"testdata/server.crt", "testdata/server.key",
@@ -136,8 +136,8 @@ func setup(
serverKeyPath string,
clientCertPath string,
clientKeyPath string,
- handler gus.Handler,
-) (gus.Server, gemini.Client, tls.Certificate) {
+ handler sr.Handler,
+) (sr.Server, gemini.Client, tls.Certificate) {
serverTLS, err := gemini.FileTLS(serverCertPath, serverKeyPath)
require.Nil(t, err)
@@ -159,7 +159,7 @@ func setup(
func clientFor(
t *testing.T,
- server gus.Server,
+ server sr.Server,
certPath string,
keyPath string,
) (gemini.Client, tls.Certificate) {
@@ -179,11 +179,11 @@ func clientFor(
}), clientCert
}
-func requestPath(t *testing.T, client gemini.Client, server gus.Server, path string) *gus.Response {
+func requestPath(t *testing.T, client gemini.Client, server sr.Server, path string) *sr.Response {
u, err := url.Parse("gemini://" + server.Address() + path)
require.Nil(t, err)
- response, err := client.RoundTrip(&gus.Request{URL: u})
+ response, err := client.RoundTrip(&sr.Request{URL: u})
require.Nil(t, err)
return response
diff --git a/contrib/tlsauth/gemini.go b/contrib/tlsauth/gemini.go
index 40bee9e..9996595 100644
--- a/contrib/tlsauth/gemini.go
+++ b/contrib/tlsauth/gemini.go
@@ -3,8 +3,8 @@ package tlsauth
import (
"context"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/gemini"
)
// GeminiAuth builds an authentication middleware from approval criteria.
@@ -12,9 +12,9 @@ import (
// If a request does not contain a client certificate it will be rejected
// with a "60 certificate required" response. If the client identity does
// not pass the approver it will be rejected with "62 certificate invalid".
-func GeminiAuth(approver Approver) gus.Middleware {
- return func(inner gus.Handler) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GeminiAuth(approver Approver) sr.Middleware {
+ return func(inner sr.Handler) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
identity := Identity(request)
if identity == nil {
return geminiMissingCert(ctx, request)
@@ -33,9 +33,9 @@ func GeminiAuth(approver Approver) gus.Middleware {
// If there is no client certificate the request will pass through the middleware.
// It will only be rejected with "62 certificate invalid" if there *is* a client
// certificate, but it fails the approval.
-func GeminiOptionalAuth(approver Approver) gus.Middleware {
- return func(inner gus.Handler) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GeminiOptionalAuth(approver Approver) sr.Middleware {
+ return func(inner sr.Handler) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
identity := Identity(request)
if identity != nil && !approver(identity) {
return geminiCertNotAuthorized(ctx, request)
@@ -49,10 +49,10 @@ func GeminiOptionalAuth(approver Approver) gus.Middleware {
// GeminiRequireCertificate is a middleware that only requires a client certificate.
var GeminiRequireCertificate = GeminiAuth(Allow)
-func geminiMissingCert(_ context.Context, _ *gus.Request) *gus.Response {
+func geminiMissingCert(_ context.Context, _ *sr.Request) *sr.Response {
return gemini.RequireCert("A client certificate is required.")
}
-func geminiCertNotAuthorized(_ context.Context, _ *gus.Request) *gus.Response {
+func geminiCertNotAuthorized(_ context.Context, _ *sr.Request) *sr.Response {
return gemini.CertAuthFailure("Client certificate not authorized.")
}
diff --git a/contrib/tlsauth/gemini_test.go b/contrib/tlsauth/gemini_test.go
index 7823de6..655307a 100644
--- a/contrib/tlsauth/gemini_test.go
+++ b/contrib/tlsauth/gemini_test.go
@@ -8,38 +8,38 @@ import (
"github.com/stretchr/testify/assert"
- "tildegit.org/tjp/gus"
- "tildegit.org/tjp/gus/contrib/tlsauth"
- "tildegit.org/tjp/gus/gemini"
+ sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/contrib/tlsauth"
+ "tildegit.org/tjp/sliderule/gemini"
)
func TestGeminiAuth(t *testing.T) {
- handler1 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler1 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, "/one") {
return nil
}
return gemini.Success("", &bytes.Buffer{})
})
- handler2 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler2 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, "/two") {
return nil
}
return gemini.Success("", &bytes.Buffer{})
})
- handler3 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler3 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, "/three") {
return nil
}
return gemini.Success("", &bytes.Buffer{})
})
- handler4 := gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ handler4 := sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
return gemini.Success("", &bytes.Buffer{})
})
- handler := gus.FallthroughHandler(
+ handler := sr.FallthroughHandler(
tlsauth.GeminiAuth(tlsauth.Allow)(handler1),
tlsauth.GeminiAuth(tlsauth.Allow)(handler2),
tlsauth.GeminiAuth(tlsauth.Reject)(handler3),
@@ -73,8 +73,8 @@ func TestGeminiAuth(t *testing.T) {
}
func TestGeminiOptionalAuth(t *testing.T) {
- pathHandler := func(path string) gus.Handler {
- return gus.HandlerFunc(func(_ context.Context, request *gus.Request) *gus.Response {
+ pathHandler := func(path string) sr.Handler {
+ return sr.HandlerFunc(func(_ context.Context, request *sr.Request) *sr.Response {
if !strings.HasPrefix(request.Path, path) {
return nil
}
@@ -82,7 +82,7 @@ func TestGeminiOptionalAuth(t *testing.T) {
})
}
- handler := gus.FallthroughHandler(
+ handler := sr.FallthroughHandler(
tlsauth.GeminiOptionalAuth(tlsauth.Allow)(pathHandler("/one")),
tlsauth.GeminiOptionalAuth(tlsauth.Allow)(pathHandler("/two")),
tlsauth.GeminiOptionalAuth(tlsauth.Reject)(pathHandler("/three")),