Skip to content

Commit 31b6bbe

Browse files
committed
Merge branch 'catatsuy-feature/noslash_redirect_re'
2 parents 228167f + 7241e86 commit 31b6bbe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

httpd.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package main
22

33
import (
4+
"encoding/base64"
45
"io"
56
"log"
67
"net"
78
"net/http"
89
"net/http/httputil"
910
"net/url"
11+
"path/filepath"
1012
"strings"
1113

12-
"encoding/base64"
13-
1414
"github.com/go-martini/martini"
1515
"github.com/martini-contrib/oauth2"
1616
"github.com/martini-contrib/sessions"
17-
"path/filepath"
1817
)
1918

2019
type Server struct {
@@ -58,11 +57,14 @@ func (s *Server) Run() error {
5857

5958
backendsFor := make(map[string][]Backend)
6059
backendIndex := make([]string, len(s.Conf.Proxies))
60+
rawPaths := make([]string, len(s.Conf.Proxies))
6161

6262
for i := range s.Conf.Proxies {
6363
p := s.Conf.Proxies[i]
6464

65+
rawPath := ""
6566
if strings.HasSuffix(p.Path, "/") == false {
67+
rawPath = p.Path
6668
p.Path += "/"
6769
}
6870
strip_path := p.Path
@@ -82,17 +84,24 @@ func (s *Server) Run() error {
8284
StripPath: strip_path,
8385
})
8486
backendIndex[i] = p.Path
87+
rawPaths[i] = rawPath
8588
log.Printf("register proxy host:%s path:%s dest:%s strip_path:%v", p.Host, strip_path, u.String(), p.Strip)
8689
}
8790

8891
registered := make(map[string]bool)
89-
for _, path := range backendIndex {
92+
for i, path := range backendIndex {
9093
if registered[path] {
9194
continue
9295
}
9396
proxy := newVirtualHostReverseProxy(backendsFor[path])
9497
m.Any(path, proxyHandleWrapper(proxy))
9598
registered[path] = true
99+
rawPath := rawPaths[i]
100+
if rawPath != "" {
101+
m.Get(rawPath, func(w http.ResponseWriter, r *http.Request) {
102+
http.Redirect(w, r, rawPath+"/", http.StatusFound)
103+
})
104+
}
96105
}
97106

98107
path, err := filepath.Abs(s.Conf.Htdocs)

0 commit comments

Comments
 (0)