~juju-qa/juju-core/1.16-packaging

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.net/websocket/hybi.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-20 22:06:08 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130920220608-298qxyybgb0n9c47
Tags: 1.14.1-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
385
385
        return
386
386
}
387
387
 
388
 
func isHybiVersion(version int) bool {
389
 
        switch version {
390
 
        case ProtocolVersionHybi08, ProtocolVersionHybi13:
391
 
                return true
392
 
        default:
393
 
        }
394
 
        return false
395
 
}
396
 
 
397
388
// Client handshake described in draft-ietf-hybi-thewebsocket-protocol-17
398
389
func hybiClientHandshake(config *Config, br *bufio.Reader, bw *bufio.Writer) (err error) {
399
 
        if !isHybiVersion(config.Version) {
400
 
                panic("wrong protocol version.")
401
 
        }
402
 
 
403
390
        bw.WriteString("GET " + config.Location.RequestURI() + " HTTP/1.1\r\n")
404
391
 
405
392
        bw.WriteString("Host: " + config.Location.Host + "\r\n")
410
397
                nonce = []byte(config.handshakeData["key"])
411
398
        }
412
399
        bw.WriteString("Sec-WebSocket-Key: " + string(nonce) + "\r\n")
413
 
        if config.Version == ProtocolVersionHybi13 {
414
 
                bw.WriteString("Origin: " + strings.ToLower(config.Origin.String()) + "\r\n")
415
 
        } else if config.Version == ProtocolVersionHybi08 {
416
 
                bw.WriteString("Sec-WebSocket-Origin: " + strings.ToLower(config.Origin.String()) + "\r\n")
 
400
        bw.WriteString("Origin: " + strings.ToLower(config.Origin.String()) + "\r\n")
 
401
 
 
402
        if config.Version != ProtocolVersionHybi13 {
 
403
                return ErrBadProtocolVersion
417
404
        }
 
405
 
418
406
        bw.WriteString("Sec-WebSocket-Version: " + fmt.Sprintf("%d", config.Version) + "\r\n")
419
407
        if len(config.Protocol) > 0 {
420
408
                bw.WriteString("Sec-WebSocket-Protocol: " + strings.Join(config.Protocol, ", ") + "\r\n")
500
488
        switch version {
501
489
        case "13":
502
490
                c.Version = ProtocolVersionHybi13
503
 
        case "8":
504
 
                c.Version = ProtocolVersionHybi08
505
491
        default:
506
492
                return http.StatusBadRequest, ErrBadWebSocketVersion
507
493
        }
536
522
        switch config.Version {
537
523
        case ProtocolVersionHybi13:
538
524
                origin = req.Header.Get("Origin")
539
 
        case ProtocolVersionHybi08:
540
 
                origin = req.Header.Get("Sec-Websocket-Origin")
541
525
        }
542
526
        if origin == "null" {
543
527
                return nil, nil