-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/ws init func (rebased on master) (#406)
* Add WebSocket init function for authorizing connect * fix handleInit * fix subscripton tests * fix code style * delete debug info * chore: change InitPayload to handle any kind of data Changing to json.RawMessage and deferring parsing until actually trying to read a value. * change ci triggers * chore: add windows to build matrix (#418) * chore: add windows to build matrix chore: use math.MaxInt instead of byte shift * chore: try to fix test for windows * chore: use goldie v2 chore: replace line ending under windows goldie assertions * chore: line ending for goldie win * chore: skip goldie on a windows * fix imports pkg * chore: fix benchmark crash chore: make defer test more predictable * chore: fix stream array test * chore: update workflow * chore: disable stream test * enable goldie * revert "chore: fix benchmark crash" disable streaming tests on windows * chore: use normalize line ending in some tests * chore: ignore kafka tests on windows * chore: add step to configure git line endings in ci * chore: skip sub+federation test for windows pipeline * skip all imports test on win * Revert "chore: use normalize line ending in some tests" * chore: cleanup * chore: use separate fixtures for win in imports pkg * chore: fix build * chore: fix imports test on win * chore: cleanup Co-authored-by: chedom <domanchukits@gmail.com> Co-authored-by: Jens Neuse <jens.neuse@gmx.de> Co-authored-by: Sergey Petrunin <spetrunin@users.noreply.github.com>
- Loading branch information
1 parent
859487a
commit a4fdba3
Showing
7 changed files
with
208 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package subscription | ||
|
||
import "encoding/json" | ||
|
||
// InitPayload is a structure that is parsed from the websocket init message payload. | ||
type InitPayload json.RawMessage | ||
|
||
// GetString safely gets a string value from the payload. It returns an empty string if the | ||
// payload is nil or the value isn't set. | ||
func (p InitPayload) GetString(key string) string { | ||
if p == nil { | ||
return "" | ||
} | ||
|
||
var payload map[string]interface{} | ||
if err := json.Unmarshal(p, &payload); err != nil { | ||
return "" | ||
} | ||
|
||
if value, ok := payload[key]; ok { | ||
res, _ := value.(string) | ||
return res | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// Authorization is a short hand for getting the Authorization header from the | ||
// payload. | ||
func (p InitPayload) Authorization() string { | ||
if value := p.GetString("Authorization"); value != "" { | ||
return value | ||
} | ||
|
||
if value := p.GetString("authorization"); value != "" { | ||
return value | ||
} | ||
|
||
return "" | ||
} |
Oops, something went wrong.