// Package testsite serves a deterministic dynamic page for demos and integration tests.
package testsite
import (
"net/http"
)
const HTML = `
CFBrowser Lab
Browser integration lab
Ready
Download CIF
`
func Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write([]byte(HTML))
})
mux.HandleFunc("/shadow", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write([]byte(`Shadow labShadow ready
`))
})
mux.HandleFunc("/long", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
height := "2200"
if r.URL.Query().Get("huge") == "1" {
height = "50000"
}
_, _ = w.Write([]byte(`Capture fixture
`))
})
mux.HandleFunc("/download", func(w http.ResponseWriter, r *http.Request) {
if c, e := r.Cookie("lab"); e != nil || c.Value != "active" {
http.Error(w, "missing session", http.StatusForbidden)
return
}
w.Header().Set("Content-Disposition", `attachment; filename="sample.cif"`)
w.Header().Set("Content-Type", "chemical/x-cif")
_, _ = w.Write([]byte("data_La2O3\n_cell_length_a 3.94\n"))
})
mux.HandleFunc("/cookie", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
value := "empty"
if c, e := r.Cookie("lab"); e == nil {
value = c.Value
}
_, _ = w.Write([]byte("cookie=" + value + "
"))
})
return mux
}