do not return Sec-WebSocket-Accept in response if upgrade error (not read yet from Request) + StatusCode getter
This commit is contained in:
parent
db2b24ae51
commit
5fcdc9ca70
|
@ -23,6 +23,12 @@ func (r *T) SetProtocol(p []byte) {
|
|||
// to the rfc from the Sec-WebSocket-Key
|
||||
func (r *T) ProcessKey(k []byte) {
|
||||
|
||||
// do nothing for empty key
|
||||
if k == nil || len(k) == 0 {
|
||||
r.accept = nil
|
||||
return
|
||||
}
|
||||
|
||||
/* (1) Concat with constant salt */
|
||||
mix := append(k, WSSalt...)
|
||||
|
||||
|
@ -48,7 +54,11 @@ func (r T) Send(w io.Writer) (int, error) {
|
|||
optionalProtocol = fmt.Sprintf("Sec-WebSocket-Protocol: %s\r\n", r.protocol)
|
||||
}
|
||||
|
||||
headers := fmt.Sprintf("Upgrade: websocket\t\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\nSec-WebSocket-Version: %d\r\n%s", r.accept, WSVersion, optionalProtocol)
|
||||
headers := fmt.Sprintf("Upgrade: websocket\t\nConnection: Upgrade\r\nSec-WebSocket-Version: %d\r\n%s", WSVersion, optionalProtocol)
|
||||
if r.accept != nil {
|
||||
headers = fmt.Sprintf("%sSec-WebSocket-Accept: %s\r\n", headers, r.accept)
|
||||
}
|
||||
headers = fmt.Sprintf("%s\r\n", headers)
|
||||
|
||||
/* (3) Build all */
|
||||
raw := []byte(fmt.Sprintf("%s%s\r\n", responseLine, headers))
|
||||
|
@ -63,4 +73,10 @@ func (r T) Send(w io.Writer) (int, error) {
|
|||
// GetProtocol returns the choosen protocol if set, else nil
|
||||
func (r T) GetProtocol() []byte {
|
||||
return r.protocol
|
||||
}
|
||||
|
||||
|
||||
// GetStatusCode returns the response status code
|
||||
func (r T) GetStatusCode() StatusCode {
|
||||
return r.code
|
||||
}
|
Loading…
Reference in New Issue