-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestserver.go
More file actions
55 lines (49 loc) · 1.39 KB
/
testserver.go
File metadata and controls
55 lines (49 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"flag"
"log"
"mime"
"net/http"
"time"
)
var (
name = flag.String(
"name",
"",
"HTTP server name (host name with optinal colon-separated port)",
)
port = flag.String(
"port",
"8888",
"port for HTTP server",
)
)
const (
timeout = time.Duration(25 * time.Second)
timeoutMsg = "Timeout Error"
)
type NeverHandler struct {}
func (nh *NeverHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// this request should always timeout!
time.Sleep(timeout)
}
func main() {
flag.Parse()
//mime.AddExtensionType(".js", "application/javascript; charset=utf-8");
mime.AddExtensionType(".js", "text/javascript; charset=utf-8");
http.Handle("/error/404", http.NotFoundHandler())
http.Handle("/error/timeout", http.TimeoutHandler(&NeverHandler{}, timeout, "Timeout"))
//http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("./"))))
http.Handle("/", http.FileServer(http.Dir("./")))
srvname := *name
displayname := srvname
if (displayname == "") {
displayname = "localhost"
}
srvname = srvname + ":" + *port
displayname = displayname + ":" + *port
log.Println("Serving test webpage at http://" + displayname + "/tests.html")
if err := http.ListenAndServe(srvname, nil); err != nil {
log.Fatal("ListenAndServe: %v", err)
}
}