@@ -56,6 +56,36 @@ func TestIsWebSocketUpgrade(t *testing.T) {
56
56
}
57
57
}
58
58
59
+ func TestSubProtocolSelection (t * testing.T ) {
60
+ upgrader := Upgrader {
61
+ Subprotocols : []string {"foo" , "bar" , "baz" },
62
+ }
63
+
64
+ r := http.Request {Header : http.Header {"Sec-Websocket-Protocol" : {"foo" , "bar" }}}
65
+ s := upgrader .selectSubprotocol (& r , nil )
66
+ if s != "foo" {
67
+ t .Errorf ("Upgrader.selectSubprotocol returned %v, want %v" , s , "foo" )
68
+ }
69
+
70
+ r = http.Request {Header : http.Header {"Sec-Websocket-Protocol" : {"bar" , "foo" }}}
71
+ s = upgrader .selectSubprotocol (& r , nil )
72
+ if s != "bar" {
73
+ t .Errorf ("Upgrader.selectSubprotocol returned %v, want %v" , s , "bar" )
74
+ }
75
+
76
+ r = http.Request {Header : http.Header {"Sec-Websocket-Protocol" : {"baz" }}}
77
+ s = upgrader .selectSubprotocol (& r , nil )
78
+ if s != "baz" {
79
+ t .Errorf ("Upgrader.selectSubprotocol returned %v, want %v" , s , "baz" )
80
+ }
81
+
82
+ r = http.Request {Header : http.Header {"Sec-Websocket-Protocol" : {"quux" }}}
83
+ s = upgrader .selectSubprotocol (& r , nil )
84
+ if s != "" {
85
+ t .Errorf ("Upgrader.selectSubprotocol returned %v, want %v" , s , "empty string" )
86
+ }
87
+ }
88
+
59
89
var checkSameOriginTests = []struct {
60
90
ok bool
61
91
r * http.Request
0 commit comments