mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-05 14:07:01 +00:00
deduplicate
This commit is contained in:
parent
f13feec8bf
commit
5f2f073a73
2 changed files with 13 additions and 13 deletions
|
@ -42,10 +42,6 @@ func (c *Context) String(raw string, status ...int) {
|
||||||
_, _ = c.RespWriter.Write([]byte(raw))
|
_, _ = c.RespWriter.Write([]byte(raw))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) IsMethod(m string) bool {
|
|
||||||
return c.Req.Method == m
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) Redirect(uri string, statusCode int) {
|
func (c *Context) Redirect(uri string, statusCode int) {
|
||||||
http.Redirect(c.RespWriter, c.Req, uri, statusCode)
|
http.Redirect(c.RespWriter, c.Req, uri, statusCode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,19 @@ func Handler(mainDomainSuffix, rawDomain string,
|
||||||
ctx.RespWriter.Header().Set("Strict-Transport-Security", hsts)
|
ctx.RespWriter.Header().Set("Strict-Transport-Security", hsts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block all methods not required for static pages
|
// Handle all http methods
|
||||||
if !ctx.IsMethod(http.MethodGet) && !ctx.IsMethod(http.MethodHead) && !ctx.IsMethod(http.MethodOptions) {
|
ctx.RespWriter.Header().Set("Allow", http.MethodGet+", "+http.MethodHead+", "+http.MethodOptions)
|
||||||
ctx.RespWriter.Header().Set("Allow", http.MethodGet+", "+http.MethodHead+", "+http.MethodOptions) // duplic 1
|
switch ctx.Req.Method {
|
||||||
|
case http.MethodOptions:
|
||||||
|
// return Allow header
|
||||||
|
ctx.RespWriter.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
case http.MethodGet,
|
||||||
|
http.MethodHead:
|
||||||
|
// end switch case and handle allowed requests
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
// Block all methods not required for static pages
|
||||||
ctx.String("Method not allowed", http.StatusMethodNotAllowed)
|
ctx.String("Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -77,12 +87,6 @@ func Handler(mainDomainSuffix, rawDomain string,
|
||||||
ctx.RespWriter.Header().Set(headerAccessControlAllowMethods, http.MethodGet+", "+http.MethodHead)
|
ctx.RespWriter.Header().Set(headerAccessControlAllowMethods, http.MethodGet+", "+http.MethodHead)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.RespWriter.Header().Set("Allow", http.MethodGet+", "+http.MethodHead+", "+http.MethodOptions) // duplic 1
|
|
||||||
if ctx.IsMethod(http.MethodOptions) {
|
|
||||||
ctx.RespWriter.WriteHeader(http.StatusNoContent)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare request information to Gitea
|
// Prepare request information to Gitea
|
||||||
targetOptions := &upstream.Options{
|
targetOptions := &upstream.Options{
|
||||||
TryIndexPages: true,
|
TryIndexPages: true,
|
||||||
|
|
Loading…
Reference in a new issue