Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ jobs:
test:
strategy:
matrix:
go-version: [1.22.x]
go-version: [1.26.x]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- run: sudo add-apt-repository ppa:inkscape.dev/stable
- run: sudo apt-get update
- run: sudo apt-get install inkscape -y
Expand Down
2 changes: 1 addition & 1 deletion cmd/violet/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *serveCmd) Usage() string {
`
}

func (s *serveCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
func (s *serveCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...any) subcommands.ExitStatus {
if s.debugLog {
logger.Logger.SetLevel(log.DebugLevel)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/violet/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *setupCmd) Usage() string {
`
}

func (s *setupCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
func (s *setupCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...any) subcommands.ExitStatus {
// get absolute path to specify files
wdAbs, err := filepath.Abs(s.wdPath)
if err != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *setupCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{})
{
Name: "RateLimit",
Prompt: &survey.Input{Message: "Rate limit", Default: "300", Help: "Number of allowed requests per minute per IP"},
Validate: func(ans interface{}) error {
Validate: func(ans any) error {
if ansStr, ok := ans.(string); ok {
_, err := strconv.ParseUint(ansStr, 10, 64)
return err
Expand Down Expand Up @@ -160,7 +160,7 @@ func (s *setupCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{})
// don't bother with this part is the api won't be listening
if answers.ApiListen != "" {
// ask for url
err = survey.AskOne(&survey.Input{Message: "API URL", Default: "api.example.com/violet", Help: "Enter the URL which should point to the internal Violet API"}, &answers.ApiUrl, survey.WithValidator(func(ans interface{}) error {
err = survey.AskOne(&survey.Input{Message: "API URL", Default: "api.example.com/violet", Help: "Enter the URL which should point to the internal Violet API"}, &answers.ApiUrl, survey.WithValidator(func(ans any) error {
if ansStr, ok := ans.(string); ok {
_, err := url.Parse(ansStr)
return err
Expand Down Expand Up @@ -202,7 +202,7 @@ func (s *setupCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{})
return subcommands.ExitSuccess
}

func listenAddressValidator(ans interface{}) error {
func listenAddressValidator(ans any) error {
if ansStr, ok := ans.(string); ok {
// empty string means disable
if ansStr == "" {
Expand Down
17 changes: 5 additions & 12 deletions router/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/1f349/violet/target"
"github.com/mrmelon54/rescheduler"
"net/http"
"slices"
"strings"
"sync"
)
Expand Down Expand Up @@ -127,12 +128,8 @@ func (m *Manager) GetAllRoutes(hosts []string) ([]target.RouteWithActive, error)
Active: row.Active,
}

for _, i := range hosts {
// if this is never true then the domain was mistakenly grabbed from the database
if a.OnDomain(i) {
s = append(s, a)
break
}
if slices.ContainsFunc(hosts, a.OnDomain) {
s = append(s, a)
}
}

Expand Down Expand Up @@ -177,12 +174,8 @@ func (m *Manager) GetAllRedirects(hosts []string) ([]target.RedirectWithActive,
Active: row.Active,
}

for _, i := range hosts {
// if this is never true then the domain was mistakenly grabbed from the database
if a.OnDomain(i) {
s = append(s, a)
break
}
if slices.ContainsFunc(hosts, a.OnDomain) {
s = append(s, a)
}
}

Expand Down
8 changes: 5 additions & 3 deletions servers/https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ func TestNewHttpsServer_RateLimit(t *testing.T) {
db, err := violet.InitDB("file:TestNewHttpsServer_RateLimit?mode=memory&cache=shared")
assert.NoError(t, err)

const rateLimit = 5

ft := &fakeTransport{}
httpsConf := &conf.Conf{
RateLimit: 5,
RateLimit: rateLimit,
Domains: &fake.Domains{},
Certs: certs.New(nil, nil, true),
Signer: fake.SnakeOilProv.KeyStore(),
Expand All @@ -43,8 +45,8 @@ func TestNewHttpsServer_RateLimit(t *testing.T) {
assert.NoError(t, err)

wg := &sync.WaitGroup{}
wg.Add(5)
for i := 0; i < 5; i++ {
wg.Add(rateLimit)
for range rateLimit {
go func() {
defer wg.Done()
rec := httptest.NewRecorder()
Expand Down
13 changes: 5 additions & 8 deletions target/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/rs/cors"
"golang.org/x/net/http/httpguts"
"io"
"maps"
"net"
"net/http"
"net/textproto"
Expand Down Expand Up @@ -70,9 +71,7 @@ func (r Route) HasFlag(flag Flags) bool {
// UpdateHeaders takes an existing set of headers and overwrites them with the
// extra headers.
func (r Route) UpdateHeaders(header http.Header) {
for k, v := range r.Headers {
header[k] = v
}
maps.Copy(header, r.Headers)
}

// ServeHTTP responds with the data proxied from the internal server to the
Expand Down Expand Up @@ -146,10 +145,8 @@ func (r Route) internalServeHTTP(rw http.ResponseWriter, req *http.Request) {
// if extra route headers are set
if r.Headers != nil {
// loop over headers
for k, v := range r.Headers {
// copy header into the internal request
req2.Header[k] = v
}
// copy header into the internal request
maps.Copy(req2.Header, r.Headers)
}

// if forward host is enabled then send the host
Expand Down Expand Up @@ -316,7 +313,7 @@ var hopHeaders = []string{
func removeHopByHopHeaders(h http.Header) {
// RFC 7230, section 6.1: Remove headers listed in the "Connection" header.
for _, f := range h["Connection"] {
for _, sf := range strings.Split(f, ",") {
for sf := range strings.SplitSeq(f, ",") {
if sf = textproto.TrimString(sf); sf != "" {
h.Del(sf)
}
Expand Down
6 changes: 3 additions & 3 deletions utils/domain-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func ReplaceSubdomainWithWildcard(domain string) (string, bool) {
// www.example.com => example.com
func GetParentDomain(domain string) (string, bool) {
// if a valid index isn't found then return false
n := strings.IndexByte(domain, '.')
if n == -1 {
_, after, ok := strings.Cut(domain, ".")
if !ok {
return "", false
}
return domain[n+1:], true
return after, true
}

// GetTopFqdn returns the top domain stripping off multiple layers of subdomains.
Expand Down
Loading