Skip to content

Commit 5596b69

Browse files
committed
Support trim slash limit. v1.0.26
1 parent b97b2e1 commit 5596b69

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

httpx-static/main.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ func run(ctx context.Context) error {
262262
flag.Var(&skeys, "skey", "the SSL key for domain")
263263
flag.Var(&scerts, "scert", "the SSL cert for domain")
264264

265+
var trimSlashLimit int
265266
var noRedirectIndex, trimLastSlash bool
266267
flag.BoolVar(&noRedirectIndex, "no-redirect-index", false, "Whether serve with index.html without redirect.")
267268
flag.BoolVar(&trimLastSlash, "trim-last-slash", false, "Whether trim last slash by HTTP redirect(302).")
269+
flag.IntVar(&trimSlashLimit, "trim-slash-limit", 0, "Only trim last slash when got enough directories.")
268270

269271
flag.Usage = func() {
270272
fmt.Println(fmt.Sprintf("Usage: %v -t http -s https -d domains -r root -e cache -l lets -k ssk -c ssc -p proxy", os.Args[0]))
@@ -327,7 +329,7 @@ func run(ctx context.Context) error {
327329
if trimLastSlash {
328330
noRedirectIndex = true
329331
}
330-
fmt.Println(fmt.Sprintf("Config trimLastSlash=%v, noRedirectIndex=%v", trimLastSlash, noRedirectIndex))
332+
fmt.Println(fmt.Sprintf("Config trimLastSlash=%v, trimSlashLimit=%v, noRedirectIndex=%v", trimLastSlash, trimSlashLimit, noRedirectIndex))
331333

332334
var proxyUrls []*url.URL
333335
proxies := make(map[string]*url.URL)
@@ -387,8 +389,10 @@ func run(ctx context.Context) error {
387389
if r.URL.RawQuery != "" {
388390
u += "?" + r.URL.RawQuery
389391
}
390-
http.Redirect(w, r, u, http.StatusFound)
391-
return
392+
if strings.Count(u, "/") >= trimSlashLimit {
393+
http.Redirect(w, r, u, http.StatusFound)
394+
return
395+
}
392396
}
393397

394398
// Append the index.html path if access a directory.

httpx-static/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func VersionMinor() int {
3535
}
3636

3737
func VersionRevision() int {
38-
return 25
38+
return 26
3939
}
4040

4141
func Version() string {

0 commit comments

Comments
 (0)