AirJD 焦点
AirJD

没有录音文件
00:00/00:00
加收藏

HTTP2 on Go1.6 by Jxck

发布者 golang
发布于 1457916327014  浏览 6557 关键词 HTTP2, Go, English 
分享到

第1页

HTTP2 on Go1.6

Go1.6 Release Party 2016 Jxck



第2页

● id: Jxck ● github: Jxck ● twitter: @jxck_ ● blog: https://blog.jxck.io ● podcast: http://mozaic.fm ● Love: music

Jack



第3页

http2 activity



#http2go (deprecated)



#mozaicfm ep2



#http2study



#wdpress vol.75 and more...



第4页

RFC7540



第5页

HTTP2 in Go1.6



第6页

net/http supports http2



第7页

before

import ( fmt log net/http

)

func main() { var s http.Server s.Addr = ":8080"

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") fmt.Fprintf(w, "Hello World")

})

log.Fatal(s.ListenAndServeTLS(cert, key)) }



第8页

after

import ( fmt log net/http

)

func main() { var s http.Server s.Addr = ":8080"

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") fmt.Fprintf(w, "Hello World")

})

log.Fatal(s.ListenAndServeTLS(cert, key)) }



第9页

you don’t need this after 1.6

$ git clone --depth=1 https://go.googlesource.com/go $HOME/gotip $ cd $HOME/gotip/src $ ./make.bash $ cd $YOUR_PROJ $ $HOME/gotip/bin/go {install,build,test}.



第10页

how http2 bundled ?



$ tree $GOROOT/src/net/http



|-- fs.go |-- fs_test.go



bundle golang.org/x/net/http2



|-- h2_bundle.go into net/http package



|-- header.go



prefixed with `http2`



|-- header_test.go



|-- http_test.go



$ bundle golang.org/x/net/http2 net/http http2





第11页

prefixed source

original bundled



第12页

inject h2 to net/http2



App



http/1.1 req/res client



TCP req/res



http/1.1 server req/res



App



req/res |

frame



http/2 client



ALPN frame



http/2 server



req/res |

frame





第13页

inside (current status rc2)



第14页

hpack

● compress http header

○ with static/dynamic table ○ with huffman encoding ○ with binary frame

● Encode Strategy

○ depends on implement

● Benchmark

○ using hpack-test-case ○ https://gist.github.com/Jxck/a2125cfc162229e4f54f



implementation ration(small is better)



go-hpack



haskell



nghttp2



node-http2



31%



31%



31%



31%



2016/2/18 benchmark script has a bug, results are updated.





第15页

Server Push

● Push data from server

○ sending PUSH_PROMISE frame

● Low Level API

○ WritePushPromise()

● High Level API

○ not yet ○ wip ? https://goo.gl/IV0fyI

// CAUTION: wip code if p, ok := w.(http2.Pusher); push && ok {

p.Push("GET", “/path/to/push”, nil) }





第16页

Flow Control

● 2 Level Flow Control

○ Stream level ○ Connection level ○ with WindowUpdate Frame

● Current Implement

○ supported ○ default sends big window update for connection ○ stream window update each 4M transfer



第17页

Priority

● Priorities Contents

○ with weight of Stream ○ make dependency tree ○ ignorable ○ ex) high for html, low for image..

● Low Level

○ WritePriority()

● High Level

○ no high level api ○ no auto priorities content like html, css, img etc ○ priority respected jQuery110209305669261273632_1457916352160 I can’t find.





第18页

Spec Coverage

● testing with h2spec

○ https://github.com/summerwind/h2spec

● toward http2.golang.org

$ h2spec -t http2.golang.org 3.5. HTTP/2 Connection Preface ✓ Sends invalid connection preface

…..

8.2. Server Push ✓ Sends a PUSH_PROMISE frame

71 tests, 58 passed, 0 skipped, 13 failed





第19页

more

● DEBUG

$ GODEBUG="http2debug=1" go run main.go $ GODEBUG="http2debug=2" go run main.go



● h2i

$ h2i jxck.io Connected to 160.16.234.102:443 ... h2i> headers (as HTTP/1.1)> GET / HTTP/1.1 (as HTTP/1.1)> Opening Stream-ID 1: ...





第20页

Go to the HTTP2!!



第21页

Jack



支持文件格式:*.pdf
上传最后阶段需要进行在线转换,可能需要1~2分钟,请耐心等待。