Skip to content

Commit

Permalink
Added HTTP headers required for gradio
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Sep 29, 2024
1 parent 5d9b9b5 commit e72bf2e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/app/container_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ func (m *ContainerManager) ProdReload(dryRun bool) error {
err = m.command.RunContainer(m.systemConfig, m.app.AppEntry, containerName,
imageName, m.port, envMap, m.getMountArgs(), m.app.Metadata.ContainerOptions)
if err != nil {
return fmt.Errorf("error building image: %w", err)
return fmt.Errorf("error starting container: %w", err)
}

containers, err = m.command.GetContainers(m.systemConfig, containerName, false)
Expand Down
9 changes: 7 additions & 2 deletions internal/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,10 @@ func (a *App) addProxyConfig(count int, router *chi.Mux, proxyDef *starlarkstruc
// disabled in proxy config
req.Host = url.Host
}

}

permsHandler := func(p *httputil.ReverseProxy) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

// If write API, check if preview/stage app is allowed access
isWriteReques := r.Method == http.MethodPost || r.Method == http.MethodPut || r.Method == http.MethodDelete
if isWriteReques {
Expand All @@ -696,6 +694,13 @@ func (a *App) addProxyConfig(count int, router *chi.Mux, proxyDef *starlarkstruc
return
}
}

r.Header.Set("X-Forwarded-Host", strings.SplitN(r.Host, ":", 1)[0])
if r.TLS != nil {
r.Header.Set("X-Forwarded-Proto", "https")
} else {
r.Header.Set("X-Forwarded-Proto", "http")
}
// use the reverse proxy to handle the request
p.ServeHTTP(w, r)
})
Expand Down
3 changes: 1 addition & 2 deletions internal/server/app_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (s *Server) verifyClientCerts(r *http.Request, authName string) error {
}

func (s *Server) MatchApp(hostHeader, matchPath string) (types.AppInfo, error) {
s.Trace().Msgf("MatchApp %s %s", hostHeader, matchPath)
//s.Trace().Msgf("MatchApp %s %s", hostHeader, matchPath)
apps, err := s.apps.GetAllApps()
if err != nil {
return types.AppInfo{}, err
Expand All @@ -504,7 +504,6 @@ func (s *Server) MatchApp(hostHeader, matchPath string) (types.AppInfo, error) {
// Check if host header matches a known domain
checkDomain := false
if hostHeader != "" && domainMap[hostHeader] {
s.Trace().Msgf("Matched domain %s", hostHeader)
checkDomain = true
}

Expand Down

0 comments on commit e72bf2e

Please sign in to comment.