( bw *bufio.Writer, u *url.URL, nonce []byte, protocols []string, extensions []httphead.Option, header HandshakeHeader, host string, )
| 280 | } |
| 281 | |
| 282 | func httpWriteUpgradeRequest( |
| 283 | bw *bufio.Writer, |
| 284 | u *url.URL, |
| 285 | nonce []byte, |
| 286 | protocols []string, |
| 287 | extensions []httphead.Option, |
| 288 | header HandshakeHeader, |
| 289 | host string, |
| 290 | ) { |
| 291 | bw.WriteString("GET ") |
| 292 | bw.WriteString(u.RequestURI()) |
| 293 | bw.WriteString(" HTTP/1.1\r\n") |
| 294 | |
| 295 | if host == "" { |
| 296 | host = u.Host |
| 297 | } |
| 298 | httpWriteHeader(bw, headerHost, host) |
| 299 | |
| 300 | httpWriteHeaderBts(bw, headerUpgrade, specHeaderValueUpgrade) |
| 301 | httpWriteHeaderBts(bw, headerConnection, specHeaderValueConnection) |
| 302 | httpWriteHeaderBts(bw, headerSecVersion, specHeaderValueSecVersion) |
| 303 | |
| 304 | // NOTE: write nonce bytes as a string to prevent heap allocation – |
| 305 | // WriteString() copy given string into its inner buffer, unlike Write() |
| 306 | // which may write p directly to the underlying io.Writer – which in turn |
| 307 | // will lead to p escape. |
| 308 | httpWriteHeader(bw, headerSecKey, btsToString(nonce)) |
| 309 | |
| 310 | if len(protocols) > 0 { |
| 311 | httpWriteHeaderKey(bw, headerSecProtocol) |
| 312 | for i, p := range protocols { |
| 313 | if i > 0 { |
| 314 | bw.WriteString(commaAndSpace) |
| 315 | } |
| 316 | bw.WriteString(p) |
| 317 | } |
| 318 | bw.WriteString(crlf) |
| 319 | } |
| 320 | |
| 321 | if len(extensions) > 0 { |
| 322 | httpWriteHeaderKey(bw, headerSecExtensions) |
| 323 | httphead.WriteOptions(bw, extensions) |
| 324 | bw.WriteString(crlf) |
| 325 | } |
| 326 | |
| 327 | if header != nil { |
| 328 | header.WriteTo(bw) |
| 329 | } |
| 330 | |
| 331 | bw.WriteString(crlf) |
| 332 | } |
| 333 | |
| 334 | func httpWriteResponseUpgrade(bw *bufio.Writer, nonce []byte, hs Handshake, header HandshakeHeaderFunc) { |
| 335 | bw.WriteString(textHeadUpgrade) |
searching dependent graphs…