repl.it
@turbio/

can it http/2?

Go

No description

fork
loading
Files
  • main.go
  • index.html
main.go
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
56
57
58
59
60
61
62
63
64
65
66
67
package main

import (
	"fmt"
	"html/template"
	"net/http"
	"time"
)

func main() {
	index := template.Must(template.ParseFiles("index.html"))

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		var sendError string
		var success bool
		var proto string

		err := r.ParseForm()
		if err != nil {
			sendError = err.Error()
		}

		url := r.Form.Get("url")

		if url == "" {
			url = "https://repl.it"
		}

		fmt.Println("checking http/2 for", url)

		client := &http.Client{
			Timeout: time.Second * 3,
		}

		res, err := client.Head(url)
		if err != nil {
			sendError = err.Error()
		} else {
			res.Body.Close()

			proto = res.Proto
			success = res.ProtoMajor >= 2
		}

		err = index.Execute(
			w,
			struct {
				Err         string
				Placeholder string
				Success     bool
				Proto       string
			}{
				sendError,
				url,
				success,
				proto,
			},
		)
		if err != nil {
			fmt.Println("template error", err)
		}
	})

	fmt.Println("listening at :8080")
	http.ListenAndServe(":8080", nil)
}
Fetching token
?