Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ type session struct {
errChan chan error
}

func connect(url, origin string, rlConf *readline.Config) error {
func connect(url, origin string, authHeader string, rlConf *readline.Config) error {
headers := make(http.Header)
headers.Add("Origin", origin)
if authHeader != "" {
headers.Add("Authorization", authHeader)
}

ws, _, err := websocket.DefaultDialer.Dial(url, headers)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Version = "0.2.1"
var options struct {
origin string
printVersion bool
authHeader string
}

func main() {
Expand All @@ -27,6 +28,7 @@ func main() {
}
rootCmd.Flags().StringVarP(&options.origin, "origin", "o", "", "websocket origin")
rootCmd.Flags().BoolVarP(&options.printVersion, "version", "v", false, "print version")
rootCmd.Flags().StringVarP(&options.authHeader, "auth_header", "a", "", "auth header, like 'Bearer $TOKEN'")

rootCmd.Execute()
}
Expand Down Expand Up @@ -67,7 +69,7 @@ func root(cmd *cobra.Command, args []string) {
historyFile = filepath.Join(user.HomeDir, ".ws_history")
}

err = connect(dest.String(), origin, &readline.Config{
err = connect(dest.String(), origin, options.authHeader, &readline.Config{
Prompt: "> ",
HistoryFile: historyFile,
})
Expand Down