forked from quic-go/quic-go
add tiles to example server and move /echo into /demo scope
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -29,6 +30,37 @@ func (b *binds) Set(v string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
http.HandleFunc("/demo/tile", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Small 40x40 png
|
||||||
|
w.Write([]byte{
|
||||||
|
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
||||||
|
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28,
|
||||||
|
0x01, 0x03, 0x00, 0x00, 0x00, 0xb6, 0x30, 0x2a, 0x2e, 0x00, 0x00, 0x00,
|
||||||
|
0x03, 0x50, 0x4c, 0x54, 0x45, 0x5a, 0xc3, 0x5a, 0xad, 0x38, 0xaa, 0xdb,
|
||||||
|
0x00, 0x00, 0x00, 0x0b, 0x49, 0x44, 0x41, 0x54, 0x78, 0x01, 0x63, 0x18,
|
||||||
|
0x61, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x01, 0xe2, 0xb8, 0x75, 0x22, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
http.HandleFunc("/demo/tiles", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
io.WriteString(w, "<html><body>")
|
||||||
|
for i := 0; i < 200; i++ {
|
||||||
|
fmt.Fprintf(w, `<img src="/demo/tile?cachebust=%d">`, i)
|
||||||
|
}
|
||||||
|
io.WriteString(w, "</body></html>")
|
||||||
|
})
|
||||||
|
|
||||||
|
http.HandleFunc("/demo/echo", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error reading body while handling /echo: %s\n", err.Error())
|
||||||
|
}
|
||||||
|
w.Write(body)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go func() {
|
go func() {
|
||||||
log.Println(http.ListenAndServe("localhost:6060", nil))
|
log.Println(http.ListenAndServe("localhost:6060", nil))
|
||||||
@@ -59,13 +91,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error reading body while handling /echo: %s\n", err.Error())
|
|
||||||
}
|
|
||||||
w.Write(body)
|
|
||||||
})
|
|
||||||
http.Handle("/", http.FileServer(http.Dir(*www)))
|
http.Handle("/", http.FileServer(http.Dir(*www)))
|
||||||
|
|
||||||
if len(bs) == 0 {
|
if len(bs) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user