Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
suchen-sci committed Nov 22, 2021
1 parent cec9cf3 commit adfa4c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pkg/object/websocketserver/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ const (
)

var (
// unCopyHeaderKey are header keys gorilla used for request.
// if copy these keys, gorilla will return error
unCopyHeaderKey = map[string]struct{}{
// headersToSkip are gorilla library's request headers, our websocket proxy should not set.
headersToSkip = map[string]struct{}{
"Upgrade": {},
"Connection": {},
"Sec-Websocket-Key": {},
Expand Down Expand Up @@ -168,8 +167,6 @@ func (p *Proxy) run() {
p.dialer = dialer
p.upgrader = defaultUpgrader

// here if use DefaultServeMux, when do inherit, will cause panic
// panic: http: multiple registrations for /
mux := http.NewServeMux()
mux.HandleFunc("/", p.handle)
addr := fmt.Sprintf(":%d", spec.Port)
Expand Down Expand Up @@ -206,15 +203,12 @@ func (p *Proxy) copyHeader(req *http.Request) http.Header {
// X-Forwarded-Host: www.example.com:8080
// X-Forwarded-Proto: https

// In gorilla package: creates a new client connection. Use requestHeader to specify the
// origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie).
// But gorilla also copy other header values into their request header.
// gorilla also set some headers for request which we should not copy.
// As a result, we copy all headers except the ones gorilla will set for their request.
// New client connection is created using [Gorilla websocket library](https://github.com/gorilla/websocket), which takes care of some of the headers.
// Let's copy copy all headers from the incoming request, except the ones gorilla will set.

requestHeader := http.Header{}
for k, values := range req.Header {
if _, ok := unCopyHeaderKey[k]; ok {
if _, ok := headersToSkip[k]; ok {
continue
}
for _, v := range values {
Expand Down
2 changes: 2 additions & 0 deletions pkg/object/websocketserver/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func TestSpecValidate(t *testing.T) {
}
}

// this certPem and keyPem come from golang crypto/tls/testdata
// with original name: example-cert.pem and example-key.pem
const certPem = `
-----BEGIN CERTIFICATE-----
MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw
Expand Down

0 comments on commit adfa4c7

Please sign in to comment.