mirror of https://github.com/goproxyio/goproxy
parent
a7bbe9e74f
commit
5aa10edcd3
4
main.go
4
main.go
|
@ -92,8 +92,8 @@ func main() {
|
||||||
log.Printf("ExcludeHost %s\n", excludeHost)
|
log.Printf("ExcludeHost %s\n", excludeHost)
|
||||||
}
|
}
|
||||||
handle = &logger{proxy.NewRouter(proxy.NewServer(new(ops)), &proxy.RouterOptions{
|
handle = &logger{proxy.NewRouter(proxy.NewServer(new(ops)), &proxy.RouterOptions{
|
||||||
Pattern: excludeHost,
|
Pattern: excludeHost,
|
||||||
Proxy: proxyHost,
|
Proxy: proxyHost,
|
||||||
DownloadRoot: downloadRoot,
|
DownloadRoot: downloadRoot,
|
||||||
})}
|
})}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,8 +20,8 @@ const ListExpire = 5 * time.Minute
|
||||||
|
|
||||||
// A RouterOps provides the proxy host and the external pattern
|
// A RouterOps provides the proxy host and the external pattern
|
||||||
type RouterOptions struct {
|
type RouterOptions struct {
|
||||||
Pattern string
|
Pattern string
|
||||||
Proxy string
|
Proxy string
|
||||||
DownloadRoot string
|
DownloadRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ type RouterOptions struct {
|
||||||
// which implements Route Filter to
|
// which implements Route Filter to
|
||||||
// routing private module or public module .
|
// routing private module or public module .
|
||||||
type Router struct {
|
type Router struct {
|
||||||
srv *Server
|
srv *Server
|
||||||
proxy *httputil.ReverseProxy
|
proxy *httputil.ReverseProxy
|
||||||
pattern string
|
pattern string
|
||||||
downloadRoot string
|
downloadRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,11 @@ func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
var ctype string
|
var ctype string
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
i := strings.Index(r.URL.Path, "/@v/")
|
i := strings.Index(r.URL.Path, "/@v/")
|
||||||
|
if i < 0 {
|
||||||
|
http.Error(w, "no such path", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
what := r.URL.Path[i+len("/@v/"):]
|
what := r.URL.Path[i+len("/@v/"):]
|
||||||
if what == "list" {
|
if what == "list" {
|
||||||
if time.Since(info.ModTime()) >= ListExpire {
|
if time.Since(info.ModTime()) >= ListExpire {
|
||||||
|
@ -119,15 +124,15 @@ func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
ext := path.Ext(what)
|
ext := path.Ext(what)
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".info":
|
case ".info":
|
||||||
ctype = "application/json"
|
ctype = "application/json"
|
||||||
case ".mod":
|
case ".mod":
|
||||||
ctype = "text/plain; charset=UTF-8"
|
ctype = "text/plain; charset=UTF-8"
|
||||||
case ".zip":
|
case ".zip":
|
||||||
ctype = "application/octet-stream"
|
ctype = "application/octet-stream"
|
||||||
default:
|
default:
|
||||||
http.Error(w, "request not recognized", http.StatusNotFound)
|
http.Error(w, "request not recognized", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", ctype)
|
w.Header().Set("Content-Type", ctype)
|
||||||
|
|
Loading…
Reference in New Issue