@ -123,6 +123,7 @@ func newServeV2Command(e *serveEnv, subcmd serveMode) *ffcli.Command {
fs . UintVar ( & e . https , "https" , 0 , "Expose an HTTPS server at the specified port (default mode)" )
fs . UintVar ( & e . https , "https" , 0 , "Expose an HTTPS server at the specified port (default mode)" )
if subcmd == serve {
if subcmd == serve {
fs . UintVar ( & e . http , "http" , 0 , "Expose an HTTP server at the specified port" )
fs . UintVar ( & e . http , "http" , 0 , "Expose an HTTP server at the specified port" )
fs . BoolVar ( & e . promoteHTTPS , "promote-https" , false , "Promote HTTP to HTTPS (default false)" )
}
}
fs . UintVar ( & e . tcp , "tcp" , 0 , "Expose a TCP forwarder to forward raw TCP packets at the specified port" )
fs . UintVar ( & e . tcp , "tcp" , 0 , "Expose a TCP forwarder to forward raw TCP packets at the specified port" )
fs . UintVar ( & e . tlsTerminatedTCP , "tls-terminated-tcp" , 0 , "Expose a TCP forwarder to forward TLS-terminated TCP packets at the specified port" )
fs . UintVar ( & e . tlsTerminatedTCP , "tls-terminated-tcp" , 0 , "Expose a TCP forwarder to forward TLS-terminated TCP packets at the specified port" )
@ -223,6 +224,11 @@ func (e *serveEnv) runServeCombined(subcmd serveMode) execFunc {
return errHelpFunc ( subcmd )
return errHelpFunc ( subcmd )
}
}
if srvType == serveTypeHTTP && e . promoteHTTPS {
fmt . Fprintf ( e . stderr ( ) , "error: --promote-https is only valid for HTTPS\n\n" )
return errHelpFunc ( subcmd )
}
sc , err := e . lc . GetServeConfig ( ctx )
sc , err := e . lc . GetServeConfig ( ctx )
if err != nil {
if err != nil {
return fmt . Errorf ( "error getting serve config: %w" , err )
return fmt . Errorf ( "error getting serve config: %w" , err )
@ -295,7 +301,7 @@ func (e *serveEnv) runServeCombined(subcmd serveMode) execFunc {
if err := e . validateConfig ( parentSC , srvPort , srvType ) ; err != nil {
if err := e . validateConfig ( parentSC , srvPort , srvType ) ; err != nil {
return err
return err
}
}
err = e . setServe ( sc , st , dnsName , srvType , srvPort , mount , args [ 0 ] , funnel )
err = e . setServe ( sc , st , dnsName , srvType , srvPort , mount , args [ 0 ] , funnel , e . promoteHTTPS )
msg = e . messageForPort ( sc , st , dnsName , srvType , srvPort )
msg = e . messageForPort ( sc , st , dnsName , srvType , srvPort )
}
}
if err != nil {
if err != nil {
@ -365,7 +371,7 @@ func serveFromPortHandler(tcp *ipn.TCPPortHandler) serveType {
}
}
}
}
func ( e * serveEnv ) setServe ( sc * ipn . ServeConfig , st * ipnstate . Status , dnsName string , srvType serveType , srvPort uint16 , mount string , target string , allowFunnel bool ) error {
func ( e * serveEnv ) setServe ( sc * ipn . ServeConfig , st * ipnstate . Status , dnsName string , srvType serveType , srvPort uint16 , mount string , target string , allowFunnel bool , promoteHTTPS bool ) error {
// update serve config based on the type
// update serve config based on the type
switch srvType {
switch srvType {
case serveTypeHTTPS , serveTypeHTTP :
case serveTypeHTTPS , serveTypeHTTP :
@ -390,6 +396,8 @@ func (e *serveEnv) setServe(sc *ipn.ServeConfig, st *ipnstate.Status, dnsName st
// update the serve config based on if funnel is enabled
// update the serve config based on if funnel is enabled
e . applyFunnel ( sc , dnsName , srvPort , allowFunnel )
e . applyFunnel ( sc , dnsName , srvPort , allowFunnel )
sc . SetRedirectToHTTPS ( dnsName , srvPort , promoteHTTPS )
return nil
return nil
}
}