Skip to content

Commit

Permalink
feat(caddy): allow to configure TLSConfig in Caddyfile
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Oct 25, 2024
1 parent 2ed8aaa commit 7470471
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 68 deletions.
20 changes: 20 additions & 0 deletions plugins/caddy/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,26 @@ func parseRedisConfiguration(c map[string]interface{}) map[string]interface{} {
}
case "ConnWriteTimeout", "MaxFlushDelay", "MinRetryBackoff", "MaxRetryBackoff", "DialTimeout", "ReadTimeout", "WriteTimeout", "PoolTimeout", "ConnMaxIdleTime", "ConnMaxLifetime":
c[k], _ = time.ParseDuration(v.(string))
case "MaxVersion", "MinVersion":
strV, _ := v.(string)
if strings.HasPrefix(strV, "TLS") {
strV = strings.Trim(strings.TrimPrefix(strV, "TLS"), " ")
}

switch strV {
case "0x0300", "SSLv3":
c[k] = 0x0300
case "0x0301", "1.0":
c[k] = 0x0301
case "0x0302", "1.1":
c[k] = 0x0302
case "0x0303", "1.2":
c[k] = 0x0303
case "0x0304", "1.3":
c[k] = 0x0304
}
case "TLSConfig":
c[k] = parseRedisConfiguration(v.(map[string]interface{}))
}
}

Expand Down
68 changes: 0 additions & 68 deletions plugins/caddy/httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -1189,68 +1186,3 @@ func TestComplexQuery(t *testing.T) {
cacheChecker(caddyTester, "fields[]=id&pagination=true", 9)
cacheChecker(caddyTester, "fields[]=id&pagination=false", 9)
}

func TestSimpleFS(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
{
admin localhost:2999
http_port 9080
cache {
ttl 5s
stale 5s
simplefs {
configuration {
size 10
path storage
}
}
}
}
localhost:9080 {
route /simplefs {
cache
respond "Hello, simplefs storage!"
}
}`, "caddyfile")

time.Sleep(time.Second)
resp1, _ := tester.AssertGetResponse(`http://localhost:9080/simplefs`, http.StatusOK, "Hello simplefs storage!")

if resp1.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/simplefs" {
t.Errorf("unexpected resp1 Cache-Status header %v", resp1.Header.Get("Cache-Status"))
}
if resp1.Header.Get("Age") != "" {
t.Errorf("unexpected resp1 Age header %v", resp1.Header.Get("Age"))
}
if _, err := os.Stat(filepath.Join("storage", url.PathEscape("GET-http-localhost:9080-/simplefs"))); os.IsNotExist(err) {
t.Errorf("impossible to check the stored file %v", err)
}

resp2, _ := tester.AssertGetResponse(`http://localhost:9080/simplefs`, http.StatusOK, "Hello simplefs storage!")

if resp1.Header.Get("Cache-Status") != "Souin; fwd=uri-miss; stored; key=GET-http-localhost:9080-/simplefs" {
t.Errorf("unexpected resp1 Cache-Status header %v", resp1.Header.Get("Cache-Status"))
}
if resp1.Header.Get("Age") != "" {
t.Errorf("unexpected resp1 Age header %v", resp1.Header.Get("Age"))
}
if _, err := os.Stat(filepath.Join("storage", url.PathEscape("GET-http-localhost:9080-/simplefs"))); os.IsNotExist(err) {
t.Errorf("impossible to check the stored file %v", err)
}

if resp2.Header.Get("Cache-Status") != "Souin; hit; ttl=4; key=GET-http-localhost:9080-/simplefs; detail=SIMPLEFS" {
t.Errorf("unexpected resp2 Cache-Status header %v", resp2.Header.Get("Cache-Status"))
}
if resp2.Header.Get("Age") != "1" {
t.Errorf("unexpected resp2 Age header %v", resp2.Header.Get("Age"))
}
if _, err := os.Stat(filepath.Join("storage", url.PathEscape("GET-http-localhost:9080-/simplefs"))); os.IsNotExist(err) {
t.Errorf("impossible to check the stored file %v", err)
}

time.Sleep(5 * time.Second)
if _, err := os.Stat(filepath.Join("storage", url.PathEscape("GET-http-localhost:9080-/simplefs"))); err == nil {
t.Errorf("the stored file %v should be deleted", err)
}
}

0 comments on commit 7470471

Please sign in to comment.