Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added headers to config for fixing ase.in.tum #1348

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions tools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ type Config struct {
Host string `yaml:"host"`
ApiKey string `yaml:"apiKey"`
} `yaml:"meili"`
VodURLTemplate string `yaml:"vodURLTemplate"`
CanonicalURL string `yaml:"canonicalURL"`
VodURLTemplate string `yaml:"vodURLTemplate"`
CanonicalURL string `yaml:"canonicalURL"`
Headers []Header `yaml:"headers"`
}

type MailConfig struct {
Expand All @@ -180,6 +181,11 @@ type MailConfig struct {
MaxMailsPerMinute int `yaml:"maxMailsPerMinute"`
}

type Header struct {
Header string `yaml:"header"`
Value string `yaml:"value"`
}

func (Config) GetJWTKey() *rsa.PrivateKey {
return jwtKey
}
Expand Down
9 changes: 9 additions & 0 deletions tools/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ type JWTClaims struct {
SamlSubjectID *string // identifier of the SAML session (if any)
}

func AddResponseHeaders() gin.HandlerFunc {
return func(c *gin.Context) {
for _, h := range Cfg.Headers {
c.Header(h.Header, h.Value)
}
c.Next()
}
}

func InitContext(daoWrapper dao.DaoWrapper) gin.HandlerFunc {
return func(c *gin.Context) {
// no context initialisation required for static assets.
Expand Down
1 change: 1 addition & 0 deletions web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func configMainRoute(router *gin.Engine) {

// watch
streamGroup.Use(tools.InitStream(daoWrapper))
streamGroup.Use(tools.AddResponseHeaders())
streamGroup.GET("/w/:slug/:streamID", routes.WatchPage)
streamGroup.GET("/w/:slug/:streamID/:version", routes.WatchPage)
streamGroup.GET("/w/:slug/:streamID/chat/popup", routes.PopOutChat)
Expand Down
Loading