Arguments from HTTP headers

This commit is contained in:
Onur Yilmaz 2019-01-29 15:44:20 +01:00
parent a080c85cbc
commit 7fb8f2c709
2 changed files with 8 additions and 4 deletions

View File

@ -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] --max-connection value Maximum connection to gotty (default: 0) [$GOTTY_MAX_CONNECTION]
--once Accept only one client and exit on disconnection [$GOTTY_ONCE] --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] --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] --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] --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] --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]

View File

@ -72,7 +72,7 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
} }
defer conn.Close() defer conn.Close()
err = server.processWSConn(ctx, conn) err = server.processWSConn(ctx, conn, r.Header)
switch err { switch err {
case ctx.Err(): case ctx.Err():
@ -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() typ, initLine, err := conn.ReadMessage()
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to authenticate websocket connection") return errors.Wrapf(err, "failed to authenticate websocket connection")
@ -109,13 +109,17 @@ func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) e
if server.options.PermitArguments && init.Arguments != "" { if server.options.PermitArguments && init.Arguments != "" {
queryPath = init.Arguments queryPath = init.Arguments
} }
headerArguments := header.Get("Arguments")
if server.options.PermitArguments && headerArguments != "" {
queryPath = queryPath + "&" + headerArguments
}
query, err := url.Parse(queryPath) query, err := url.Parse(queryPath)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to parse arguments") return errors.Wrapf(err, "failed to parse arguments")
} }
params := query.Query() params := query.Query()
var slave Slave var slave Slave
slave, err = server.factory.New(params) slave, err = server.factory.New(params)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create backend") return errors.Wrapf(err, "failed to create backend")