@@ -82,20 +82,35 @@ func setProxyDirector(proxy *httputil.ReverseProxy) {
8282 req.URL.RawQuery = ""
8383 }
8484}
85+func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
86+ return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath)))
87+}
8588
8689func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
8790 serveMux := http.NewServeMux()
8891 for _, u := range opts.proxyUrls {
8992 path := u.Path
90− u.Path = ""
91− log.Printf("mapping path %q => upstream %q", path, u)
92− proxy := NewReverseProxy(u)
93− if !opts.PassHostHeader {
94− setProxyUpstreamHostHeader(proxy, u)
95− } else {
96− setProxyDirector(proxy)
93+ switch u.Scheme {
94+ case "http", "https":
95+ u.Path = ""
96+ log.Printf("mapping path %q => upstream %q", path, u)
97+ proxy := NewReverseProxy(u)
98+ if !opts.PassHostHeader {
99+ setProxyUpstreamHostHeader(proxy, u)
100+ } else {
101+ setProxyDirector(proxy)
102+ }
103+ serveMux.Handle(path, &UpstreamProxy{u.Host, proxy})
104+ case "file":
105+ if u.Fragment != "" {
106+ path = u.Fragment
107+ }
108+ log.Printf("mapping path %q => file system %q", path, u.Path)
109+ proxy := NewFileServer(path, u.Path)
110+ serveMux.Handle(path, &UpstreamProxy{path, proxy})
111+ default:
112+ panic(fmt.Sprintf("unknown upstream protocol %s", u.Scheme))
97113 }
98− serveMux.Handle(path, &UpstreamProxy{u.Host, proxy})
99114 }
100115 for _, u := range opts.CompiledRegex {
101116 log.Printf("compiled skip-auth-regex => %q", u)