Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: experimental/webtry/webtry.go

Issue 298433002: Add gzip encoding responses. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/webtry/setup/continue_install ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/webtry/webtry.go
diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go
index bf352fb13178b0573a4128365f8695a1ac255c19..4c340142fb70a7ce3078c3babec9107d87a52ea9 100644
--- a/experimental/webtry/webtry.go
+++ b/experimental/webtry/webtry.go
@@ -8,8 +8,6 @@ import (
"encoding/json"
"flag"
"fmt"
- _ "github.com/go-sql-driver/mysql"
- _ "github.com/mattn/go-sqlite3"
htemplate "html/template"
"io/ioutil"
"log"
@@ -24,6 +22,12 @@ import (
"time"
)
+import (
+ "github.com/fiorix/go-web/autogzip"
+ _ "github.com/go-sql-driver/mysql"
+ _ "github.com/mattn/go-sqlite3"
+)
+
const (
RESULT_COMPILE = `../../experimental/webtry/safec++ -DSK_GAMMA_SRGB -DSK_GAMMA_APPLY_TO_A8 -DSK_SCALAR_TO_FLOAT_EXCLUDED -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1 -DSK_SUPPORT_GPU=0 -DSK_SUPPORT_OPENCL=0 -DSK_FORCE_DISTANCEFIELD_FONTS=0 -DSK_SCALAR_IS_FLOAT -DSK_CAN_USE_FLOAT -DSK_SAMPLES_FOR_X -DSK_BUILD_FOR_UNIX -DSK_USE_POSIX_THREADS -DSK_SYSTEM_ZLIB=1 -DSK_DEBUG -DSK_DEVELOPER=1 -I../../src/core -I../../src/images -I../../tools/flags -I../../include/config -I../../include/core -I../../include/pathops -I../../include/pipe -I../../include/effects -I../../include/ports -I../../src/sfnt -I../../include/utils -I../../src/utils -I../../include/images -g -fno-exceptions -fstrict-aliasing -Wall -Wextra -Winit-self -Wpointer-arith -Wno-unused-parameter -m64 -fno-rtti -Wnon-virtual-dtor -c ../../../cache/%s.cpp -o ../../../cache/%s.o`
LINK = `../../experimental/webtry/safec++ -m64 -lstdc++ -lm -o ../../../inout/%s -Wl,--start-group ../../../cache/%s.o obj/experimental/webtry/webtry.main.o obj/gyp/libflags.a libskia_images.a libskia_core.a libskia_effects.a obj/gyp/libjpeg.a obj/gyp/libwebp_dec.a obj/gyp/libwebp_demux.a obj/gyp/libwebp_dsp.a obj/gyp/libwebp_enc.a obj/gyp/libwebp_utils.a libskia_utils.a libskia_opts.a libskia_opts_ssse3.a libskia_ports.a libskia_sfnt.a -Wl,--end-group -lpng -lz -lgif -lpthread -lfontconfig -ldl -lfreetype`
@@ -328,6 +332,7 @@ func doCmd(commandLine string, moveToDebug bool) (string, error) {
// reportError formats an HTTP error response and also logs the detailed error message.
func reportError(w http.ResponseWriter, r *http.Request, err error, message string) {
log.Printf("Error: %s\n%s", message, err.Error())
+ w.Header().Set("Content-Type", "text/plain")
http.Error(w, message, 500)
}
@@ -343,6 +348,7 @@ func reportTryError(w http.ResponseWriter, r *http.Request, err error, message,
http.Error(w, "Failed to serialize a response", 500)
return
}
+ w.Header().Set("Content-Type", "text/plain")
w.Write(resp)
}
@@ -373,6 +379,7 @@ func imageHandler(w http.ResponseWriter, r *http.Request) {
return
}
filename := match[1]
+ w.Header().Set("Content-Type", "image/png")
http.ServeFile(w, r, fmt.Sprintf("../../../inout/%s", filename))
}
@@ -406,6 +413,7 @@ func recentHandler(w http.ResponseWriter, r *http.Request) {
}
recent = append(recent, Try{Hash: hash, CreateTS: create_ts.Format("2006-02-01")})
}
+ w.Header().Set("Content-Type", "text/html")
if err := recentTemplate.Execute(w, Recent{Tries: recent, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}); err != nil {
log.Printf("ERROR: Failed to expand template: %q\n", err)
}
@@ -476,6 +484,7 @@ func workspaceHandler(w http.ResponseWriter, r *http.Request) {
hash = tries[len(tries)-1].Hash
code, _ = getCode(hash)
}
+ w.Header().Set("Content-Type", "text/html")
if err := workspaceTemplate.Execute(w, Workspace{Tries: tries, Code: code, Name: name, Hash: hash, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}); err != nil {
log.Printf("ERROR: Failed to expand template: %q\n", err)
}
@@ -529,6 +538,7 @@ func iframeHandler(w http.ResponseWriter, r *http.Request) {
return
}
// Expand the template.
+ w.Header().Set("Content-Type", "text/html")
if err := iframeTemplate.Execute(w, userCode{Code: code, Hash: hash}); err != nil {
log.Printf("ERROR: Failed to expand template: %q\n", err)
}
@@ -596,6 +606,7 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
}
}
// Expand the template.
+ w.Header().Set("Content-Type", "text/html")
if err := indexTemplate.Execute(w, userCode{Code: code, Hash: hash, Titlebar: Titlebar{GitHash: gitHash, GitInfo: gitInfo}}); err != nil {
log.Printf("ERROR: Failed to expand template: %q\n", err)
}
@@ -675,23 +686,24 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
reportTryError(w, r, err, "Failed to serialize a response.", hash)
return
}
+ w.Header().Set("Content-Type", "application/json")
w.Write(resp)
}
}
func main() {
flag.Parse()
- http.HandleFunc("/i/", imageHandler)
- http.HandleFunc("/w/", workspaceHandler)
- http.HandleFunc("/recent/", recentHandler)
- http.HandleFunc("/iframe/", iframeHandler)
- http.HandleFunc("/json/", tryInfoHandler)
+ http.HandleFunc("/i/", autogzip.HandleFunc(imageHandler))
+ http.HandleFunc("/w/", autogzip.HandleFunc(workspaceHandler))
+ http.HandleFunc("/recent/", autogzip.HandleFunc(recentHandler))
+ http.HandleFunc("/iframe/", autogzip.HandleFunc(iframeHandler))
+ http.HandleFunc("/json/", autogzip.HandleFunc(tryInfoHandler))
// Resources are served directly
// TODO add support for caching/etags/gzip
- http.Handle("/res/", http.FileServer(http.Dir("./")))
+ http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./"))))
// TODO Break out /c/ as it's own handler.
- http.HandleFunc("/", mainHandler)
+ http.HandleFunc("/", autogzip.HandleFunc(mainHandler))
log.Fatal(http.ListenAndServe(*port, nil))
}
« no previous file with comments | « experimental/webtry/setup/continue_install ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698