diff --git a/apple-touch-icon.png b/apple-touch-icon.png new file mode 100644 index 0000000..40151a0 Binary files /dev/null and b/apple-touch-icon.png differ diff --git a/assets/images/logo.jpg b/assets/images/logo.jpg new file mode 100644 index 0000000..84a5896 Binary files /dev/null and b/assets/images/logo.jpg differ diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..f0264e8 Binary files /dev/null and b/favicon.ico differ diff --git a/go.mod b/go.mod index 80a3e85..a3e2a1a 100644 --- a/go.mod +++ b/go.mod @@ -2,12 +2,13 @@ module github.com/goproxy/goproxy.cn require ( github.com/BurntSushi/toml v0.3.1 + github.com/air-gases/cacheman v0.7.4 github.com/air-gases/defibrillator v0.12.4 github.com/air-gases/limiter v0.12.4 github.com/air-gases/logger v0.12.4 github.com/air-gases/redirector v0.12.4 github.com/aofei/air v0.12.4 - github.com/goproxy/goproxy v0.0.0-20190809144859-080f99010796 + github.com/goproxy/goproxy v0.0.0-20190812143559-921935e9a7e6 github.com/mitchellh/mapstructure v1.1.2 github.com/rs/zerolog v1.14.3 ) diff --git a/go.sum b/go.sum index 74ec9ec..1fdb0ec 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdII github.com/VictoriaMetrics/fastcache v1.5.1 h1:qHgHjyoNFV7jgucU8QZUuU4gcdhfs8QW1kw68OD2Lag= github.com/VictoriaMetrics/fastcache v1.5.1/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v49daAVERr0H3CuscE= github.com/a8m/mark v0.1.1-0.20170507133748-44f2db618845/go.mod h1:c8Mh99Cw82nrsAnPgxQSZHkswVOJF7/MqZb1ZdvriLM= +github.com/air-gases/cacheman v0.7.4 h1:YHPAHhTqM35p5e2wqmmPvOI8cH2qOrpd8vLJk10J2Wo= +github.com/air-gases/cacheman v0.7.4/go.mod h1:TJmesy/aTLt4S/pobyCsoL3YQxH2yqdnMolO+WNqmSU= github.com/air-gases/defibrillator v0.12.4 h1:HF0f2sRiUgMjo/Zis7Qk5QGqWxQanqyZvMzorx/Ptfg= github.com/air-gases/defibrillator v0.12.4/go.mod h1:aE/1W3C8pHIrA5UnCDOZc8GymWzmIMkM+GNauLIGDa4= github.com/air-gases/limiter v0.12.4 h1:8fbuWeEbCw7Ge4NEu/JGJuSdDJu5i1r+BjSRR1KQNNg= @@ -42,8 +44,8 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4= github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/goproxy/goproxy v0.0.0-20190809144859-080f99010796 h1:W+BJrnBAHlS2vKFBnEOWM3Qa+qgLDdfMaDHollJgc1A= -github.com/goproxy/goproxy v0.0.0-20190809144859-080f99010796/go.mod h1:rfiiqmbdu8wueRXcp96RTer4wRcBb23lUtdNghyaOas= +github.com/goproxy/goproxy v0.0.0-20190812143559-921935e9a7e6 h1:XnIh7jsnREGCHoDsiZnC8JEwrxoad72ATvimcW5B9QA= +github.com/goproxy/goproxy v0.0.0-20190812143559-921935e9a7e6/go.mod h1:rfiiqmbdu8wueRXcp96RTer4wRcBb23lUtdNghyaOas= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= diff --git a/handler/handler.go b/handler/handler.go index f195917..c32ca29 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -3,14 +3,27 @@ package handler import ( "net/http" + "github.com/air-gases/cacheman" "github.com/aofei/air" "github.com/goproxy/goproxy" "github.com/goproxy/goproxy.cn/cfg" "github.com/goproxy/goproxy/cacher" ) -// a is the `air.Default`. -var a = air.Default +var ( + // a is the `air.Default`. + a = air.Default + + // getHeadMethods is an array contains the GET and the HEAD methods. + getHeadMethods = []string{http.MethodGet, http.MethodHead} + + // cachemanGas is used to manage the Cache-Control header. + cachemanGas = cacheman.Gas(cacheman.GasConfig{ + Public: true, + MaxAge: 3600, + SMaxAge: -1, + }) +) func init() { g := goproxy.New() @@ -24,11 +37,11 @@ func init() { g.ErrorLogger = a.ErrorLogger - a.BATCH( - []string{http.MethodGet, http.MethodHead}, - "/", - indexPageHandler, - ) + a.FILE("/robots.txt", "robots.txt") + a.FILE("/favicon.ico", "favicon.ico", cachemanGas) + a.FILE("/apple-touch-icon.png", "apple-touch-icon.png", cachemanGas) + a.FILES("/assets", a.CofferAssetRoot, cachemanGas) + a.BATCH(getHeadMethods, "/", indexPageHandler, cachemanGas) a.BATCH(nil, "/*", air.WrapHTTPHandler(g)) } diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..769dad9 --- /dev/null +++ b/robots.txt @@ -0,0 +1,7 @@ +User-Agent: * +Disallow: /*/@latest +Disallow: /*/@v/list +Disallow: /*/@v/*.info +Disallow: /*/@v/*.mod +Disallow: /*/@v/*.zip +Disallow: /sumdb/