1 Commits
v0.1 ... v0.2

Author SHA1 Message Date
bel
ff3ed3a57e gzip 2020-01-26 18:07:28 +00:00

View File

@@ -3,6 +3,7 @@ package server
import (
"fmt"
"io"
"local/gziphttp"
"local/router"
"local/todo-server/config"
"log"
@@ -20,78 +21,20 @@ func (s *Server) Routes() error {
}{
{
path: "/",
handler: s.index,
handler: s.gzip(s.index),
},
{
path: "/mytinytodo_lang.php",
handler: s.lang,
handler: s.gzip(s.lang),
},
{
path: fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard),
handler: s.phpProxy,
handler: s.gzip(s.phpProxy),
},
{
path: "/ajax.php",
handler: s.HandleAjax,
handler: s.gzip(s.HandleAjax),
},
/*
{
path: "db/index.html",
handler: s.static,
},
{
path: "jquery/index.html",
handler: s.static,
},
{
path: "lang/index.html",
handler: s.static,
},
{
path: "themes/index.html",
handler: s.static,
},
{
path: "tmp/index.html",
handler: s.static,
},
{
path: "jquery/jquery-1.4.4.min.js",
handler: s.static,
},
{
path: "jquery/jquery-ui-1.8.7.custom.min.js",
handler: s.static,
},
{
path: "jquery/jquery.autocomplete-1.1.js",
handler: s.static,
},
{
path: "mytinytodo.js",
handler: s.static,
},
{
path: "mytinytodo_ajax_storage.js",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/pda.css",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/print.css",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/style.css",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/style_rtl.css",
handler: s.static,
},
*/
}
for _, route := range routes {
@@ -161,3 +104,17 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
func (s *Server) static(w http.ResponseWriter, r *http.Request) {
s.fileServer.ServeHTTP(w, r)
}
func (s *Server) gzip(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if gziphttp.Can(r) {
gz := gziphttp.New(w)
defer gz.Close()
w = gz
}
if filepath.Ext(r.URL.Path) == ".css" {
w.Header().Set("Content-Type", "text/css; charset=utf-8")
}
h(w, r)
}
}