Merge pull request #112 from gyson/improve-websocket-support
Improve websocket support
This commit is contained in:
commit
a38b0dcec2
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Changes since v3.1.0
|
## Changes since v3.1.0
|
||||||
|
|
||||||
|
- [#112](https://github.com/pusher/oauth2_proxy/pull/112) Improve websocket support (@gyson)
|
||||||
- [#63](https://github.com/pusher/oauth2_proxy/pull/63) Use encoding/json for SessionState serialization (@yaegashi)
|
- [#63](https://github.com/pusher/oauth2_proxy/pull/63) Use encoding/json for SessionState serialization (@yaegashi)
|
||||||
- Use JSON to encode session state to be stored in browser cookies
|
- Use JSON to encode session state to be stored in browser cookies
|
||||||
- Implement legacy decode function to support existing cookies generated by older versions
|
- Implement legacy decode function to support existing cookies generated by older versions
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -32,6 +34,14 @@ func (l *responseLogger) Header() http.Header {
|
|||||||
return l.w.Header()
|
return l.w.Header()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support Websocket
|
||||||
|
func (l *responseLogger) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err error) {
|
||||||
|
if hj, ok := l.w.(http.Hijacker); ok {
|
||||||
|
return hj.Hijack()
|
||||||
|
}
|
||||||
|
return nil, nil, errors.New("http.Hijacker is not available on writer")
|
||||||
|
}
|
||||||
|
|
||||||
// ExtractGAPMetadata extracts and removes GAP headers from the ResponseWriter's
|
// ExtractGAPMetadata extracts and removes GAP headers from the ResponseWriter's
|
||||||
// Header
|
// Header
|
||||||
func (l *responseLogger) ExtractGAPMetadata() {
|
func (l *responseLogger) ExtractGAPMetadata() {
|
||||||
|
@ -24,6 +24,11 @@ func TestLoggingHandler_ServeHTTP(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
handler := func(w http.ResponseWriter, req *http.Request) {
|
handler := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
_, ok := w.(http.Hijacker)
|
||||||
|
if !ok {
|
||||||
|
t.Error("http.Hijacker is not available")
|
||||||
|
}
|
||||||
|
|
||||||
w.Write([]byte("test"))
|
w.Write([]byte("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ func (u *UpstreamProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
r.Header.Set("GAP-Auth", w.Header().Get("GAP-Auth"))
|
r.Header.Set("GAP-Auth", w.Header().Get("GAP-Auth"))
|
||||||
u.auth.SignRequest(r)
|
u.auth.SignRequest(r)
|
||||||
}
|
}
|
||||||
if u.wsHandler != nil && r.Header.Get("Connection") == "Upgrade" && r.Header.Get("Upgrade") == "websocket" {
|
if u.wsHandler != nil && strings.ToLower(r.Header.Get("Connection")) == "upgrade" && r.Header.Get("Upgrade") == "websocket" {
|
||||||
u.wsHandler.ServeHTTP(w, r)
|
u.wsHandler.ServeHTTP(w, r)
|
||||||
} else {
|
} else {
|
||||||
u.handler.ServeHTTP(w, r)
|
u.handler.ServeHTTP(w, r)
|
||||||
|
Loading…
Reference in New Issue
Block a user