| 1 | module http |
| 2 | |
| 3 | // ALPN negotiation on the Windows SChannel backend (vlang/v#27383). |
| 4 | // |
| 5 | // The wire-encoding test runs anywhere on Windows. The negotiation tests are |
| 6 | // network-dependent: run with `-d network`, e.g. |
| 7 | // v -d network test vlib/net/http/vschannel_alpn_windows_test.v |
| 8 | |
| 9 | fn test_alpn_wire_encoding() { |
| 10 | mut want := [u8(0x02)] |
| 11 | want << 'h2'.bytes() |
| 12 | want << 0x08 |
| 13 | want << 'http/1.1'.bytes() |
| 14 | assert alpn_wire(['h2', 'http/1.1']) == want |
| 15 | // Empty and over-long (>255) names are skipped. |
| 16 | assert alpn_wire([]string{}) == []u8{} |
| 17 | assert alpn_wire(['', 'h2']) == [u8(0x02), 0x68, 0x32] // 0x68='h', 0x32='2' |
| 18 | } |
| 19 | |
| 20 | fn test_schannel_alpn_negotiates_h2() { |
| 21 | $if !network ? { |
| 22 | return |
| 23 | } |
| 24 | // A public HTTP/2 server must select `h2` when offered. |
| 25 | selected := schannel_alpn_probe('www.google.com', 443, ['h2', 'http/1.1'], false) |
| 26 | assert selected == 'h2', 'expected h2, got "${selected}"' |
| 27 | } |
| 28 | |
| 29 | fn test_schannel_alpn_falls_back_to_http1() { |
| 30 | $if !network ? { |
| 31 | return |
| 32 | } |
| 33 | // Offer only HTTP/1.1: the server must not select h2. |
| 34 | selected := schannel_alpn_probe('www.google.com', 443, ['http/1.1'], false) |
| 35 | assert selected == 'http/1.1', 'expected http/1.1, got "${selected}"' |
| 36 | } |
| 37 | |