Skip to content
Permalink
Browse files

Add option to disable transport wrapping and keep CORS headers - fixes

…#75

Signed-off-by: Viktor Adam <rycus86@gmail.com>
  • Loading branch information...
rycus86 authored and alexellis committed Jul 24, 2019
1 parent 6d97e9d commit 2f5e458d062e55dda9f08109f7b2c3c6919fcdf9
Showing with 12 additions and 1 deletion.
  1. +1 −0 README.md
  2. +8 −0 cmd/server.go
  3. +3 −1 pkg/server/server.go
@@ -67,6 +67,7 @@ Feel free to open issues if you have comments, suggestions or contributions.
* The default configuration uses websockets without SSL `ws://`, but to enable encryption you could enable SSL `wss://`
* A timeout for requests can be configured via args on the server
* ~~The upstream URL has to be configured on both server and client until a discovery or service advertisement mechanism is added~~ The client can advertise upstream URLs, which it can serve
* The tunnel transport is wrapped by default which strips CORS headers from responses, but you can disable it with the `--disable-transport-wrapping` flag on the server

### Video demo

@@ -16,6 +16,7 @@ func init() {
serverCmd.Flags().StringP("token", "t", "", "token for authentication")
serverCmd.Flags().Bool("print-token", true, "prints the token in server mode")
serverCmd.Flags().StringP("token-from", "f", "", "read the authentication token from a file")
serverCmd.Flags().Bool("disable-transport-wrapping", false, "disable wrapping the transport that removes CORS headers for example")
}

// serverCmd represents the server sub command.
@@ -66,9 +67,16 @@ func runServer(cmd *cobra.Command, _ []string) error {
return errors.Wrap(err, "failed to get the 'port' value.")
}

disableWrapTransport, err := cmd.Flags().GetBool("disable-transport-wrapping")
if err != nil {
return errors.Wrap(err, "failed to get the 'disable-transport-wrapping' value.")
}

inletsServer := server.Server{
Port: port,
Token: token,

DisableWrapTransport: disableWrapTransport,
}

inletsServer.Serve()
@@ -20,6 +20,8 @@ type Server struct {
Token string
router router.Router
server *remotedialer.Server

DisableWrapTransport bool
}

// Serve traffic
@@ -56,7 +58,7 @@ func (s *Server) proxy(w http.ResponseWriter, r *http.Request) {
u.Host = r.Host
u.Scheme = route.Scheme

httpProxy := proxy.NewUpgradeAwareHandler(&u, route.Transport, true, false, s)
httpProxy := proxy.NewUpgradeAwareHandler(&u, route.Transport, !s.DisableWrapTransport, false, s)
httpProxy.ServeHTTP(w, r)
}

0 comments on commit 2f5e458

Please sign in to comment.
You can’t perform that action at this time.