Skip to content

Instantly share code, notes, and snippets.

@netroy
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netroy/1f60d100dbbd3243e816 to your computer and use it in GitHub Desktop.
Save netroy/1f60d100dbbd3243e816 to your computer and use it in GitHub Desktop.
martini + spdy + gzip
package main
import (
"log"
"net/http"
"github.com/SlyMarbo/spdy"
"io"
"compress/gzip"
"strings"
)
func hello(response http.ResponseWriter, request *http.Request) {
response.Header().Set("Content-Type", "text/plain")
var writer io.Writer = response
if spdy.UsingSPDY(response) || strings.Contains(request.Header.Get("Accept-Encoding"), "gzip") {
response.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(response)
defer gz.Close()
writer = gz
}
response.WriteHeader(200)
writer.Write([]byte("Hello world"))
}
func main() {
http.HandleFunc("/", hello)
log.Fatal(spdy.ListenAndServeTLS(":4443", "cert.pem", "cert.key", nil))
}
package main
import (
"log"
"net/http"
"github.com/SlyMarbo/spdy"
"github.com/go-martini/martini"
"io"
"compress/gzip"
"strings"
)
func hello(response http.ResponseWriter, request *http.Request) {
response.Header().Set("Content-Type", "text/plain")
var writer io.Writer = response
if spdy.UsingSPDY(response) || strings.Contains(request.Header.Get("Accept-Encoding"), "gzip") {
response.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(response)
defer gz.Close()
writer = gz
}
response.WriteHeader(200)
writer.Write([]byte("Hello world"))
}
func main() {
handler := martini.Classic()
handler.Any("/", hello)
log.Fatal(spdy.ListenAndServeTLS(":4443", "cert.pem", "cert.key", handler))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment