Skip to content

Commit

Permalink
Arguments from HTTP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
onuryilmaz committed Jan 29, 2019
1 parent a080c85 commit 7fb8f2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ By default, GoTTY starts a web server at port 8080. Open the URL on your web bro
--max-connection value Maximum connection to gotty (default: 0) [$GOTTY_MAX_CONNECTION]
--once Accept only one client and exit on disconnection [$GOTTY_ONCE]
--timeout value Timeout seconds for waiting a client(0 to disable) (default: 0) [$GOTTY_TIMEOUT]
--permit-arguments Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB) [$GOTTY_PERMIT_ARGUMENTS]
--permit-arguments Permit clients to send command line arguments in URL or in Arguments HTTP header (e.g. http://example.com:8080/?arg=AAA&arg=BBB) [$GOTTY_PERMIT_ARGUMENTS]
--width value Static width of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_WIDTH]
--height value Static height of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_HEIGHT]
--ws-origin value A regular expression that matches origin URLs to be accepted by WebSocket. No cross origin requests are acceptable by default [$GOTTY_WS_ORIGIN]
Expand Down
10 changes: 7 additions & 3 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
}
defer conn.Close()

err = server.processWSConn(ctx, conn)
err = server.processWSConn(ctx, conn, r.Header)

switch err {
case ctx.Err():
Expand All @@ -87,7 +87,7 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
}
}

func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) error {
func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn, header http.Header) error {
typ, initLine, err := conn.ReadMessage()
if err != nil {
return errors.Wrapf(err, "failed to authenticate websocket connection")
Expand All @@ -109,13 +109,17 @@ func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) e
if server.options.PermitArguments && init.Arguments != "" {
queryPath = init.Arguments
}

headerArguments := header.Get("Arguments")
if server.options.PermitArguments && headerArguments != "" {
queryPath = queryPath + "&" + headerArguments
}
query, err := url.Parse(queryPath)
if err != nil {
return errors.Wrapf(err, "failed to parse arguments")
}
params := query.Query()
var slave Slave

slave, err = server.factory.New(params)
if err != nil {
return errors.Wrapf(err, "failed to create backend")
Expand Down

0 comments on commit 7fb8f2c

Please sign in to comment.