😊
【Go】HTTP/2 サーバーをデバッグモードで動かす
サーバーの起動時に環境変数 GODEBUG
を設定する
GODEBUG=http2debug=2 go run server.go
ほかにHTTP/2 を無効にすることもできる
GODEBUG=http2server=0 go run server.go
server.go
package main
import (
"fmt"
"net/http"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, world!\r\n")
}
func main() {
http.HandleFunc("/", helloHandler)
// http.ListenAndServe(":8000", nil)
http.ListenAndServeTLS(":8080", "localhost.pem", "localhost-key.pem", nil)
}
curl で GET リクエストを送信すると次のようにログを表示してくれる
2024/07/05 10:48:51 http2: server connection from 127.0.0.1:44164 on 0xc000142000
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: wrote SETTINGS len=30, settings: MAX_FRAME_SIZE=1048576, MAX_CONCURRENT_STREAMS=250, MAX_HEADER_LIST_SIZE=1048896, HEADER_TABLE_SIZE=4096, INITIAL_WINDOW_SIZE=1048576
2024/07/05 10:48:51 http2: server: client 127.0.0.1:44164 said hello
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: read SETTINGS len=18, settings: MAX_CONCURRENT_STREAMS=100, INITIAL_WINDOW_SIZE=33554432, ENABLE_PUSH=0
2024/07/05 10:48:51 http2: server read frame SETTINGS len=18, settings: MAX_CONCURRENT_STREAMS=100, INITIAL_WINDOW_SIZE=33554432, ENABLE_PUSH=0
2024/07/05 10:48:51 http2: server processing setting [MAX_CONCURRENT_STREAMS = 100]
2024/07/05 10:48:51 http2: server processing setting [INITIAL_WINDOW_SIZE = 33554432]
2024/07/05 10:48:51 http2: server processing setting [ENABLE_PUSH = 0]
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: read WINDOW_UPDATE len=4 (conn) incr=33488897
2024/07/05 10:48:51 http2: server read frame WINDOW_UPDATE len=4 (conn) incr=33488897
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: read HEADERS flags=END_STREAM|END_HEADERS stream=1 len=30
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: wrote SETTINGS flags=ACK len=0
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: wrote WINDOW_UPDATE len=4 (conn) incr=983041
2024/07/05 10:48:51 http2: decoded hpack field header field ":method" = "GET"
2024/07/05 10:48:51 http2: decoded hpack field header field ":path" = "/"
2024/07/05 10:48:51 http2: decoded hpack field header field ":scheme" = "https"
2024/07/05 10:48:51 http2: decoded hpack field header field ":authority" = "localhost:8080"
2024/07/05 10:48:51 http2: decoded hpack field header field "user-agent" = "curl/7.88.1"
2024/07/05 10:48:51 http2: decoded hpack field header field "accept" = "*/*"
2024/07/05 10:48:51 http2: server read frame HEADERS flags=END_STREAM|END_HEADERS stream=1 len=30
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: read SETTINGS flags=ACK len=0
2024/07/05 10:48:51 http2: server read frame SETTINGS flags=ACK len=0
2024/07/05 10:48:51 http2: server encoding header ":status" = "200"
2024/07/05 10:48:51 http2: server encoding header "content-type" = "text/plain; charset=utf-8"
2024/07/05 10:48:51 http2: server encoding header "content-length" = "15"
2024/07/05 10:48:51 http2: server encoding header "date" = "Fri, 05 Jul 2024 01:48:51 GMT"
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: wrote HEADERS flags=END_HEADERS stream=1 len=49
2024/07/05 10:48:51 http2: Framer 0xc00013e2a0: wrote DATA flags=END_STREAM stream=1 len=15 data="Hello, world!\r\n"
Discussion