mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:56:14 +01:00
[BRANDING] add X-Forgejo-* headers
(cherry picked from commit0a3388f93f
) (cherry picked from commit7eba0a440a
) (cherry picked from commiteb9646c7ef
) (cherry picked from commitf1972578f5
) Conflicts: (cherry picked from commit7f96222fb4
) (cherry picked from commite3c7c9fe7b
) (cherry picked from commit84fdead902
) (cherry picked from commit85148e1196
) (cherry picked from commitc0086bd70d
) (cherry picked from commitd1e31ef318
) (cherry picked from commit681d3ed5c4
)
This commit is contained in:
parent
b58f775fa2
commit
76a3001f5b
6 changed files with 25 additions and 2 deletions
|
@ -32,6 +32,7 @@ func SetCacheControlInHeader(h http.Header, maxAge time.Duration, additionalDire
|
||||||
|
|
||||||
// to remind users they are using non-prod setting.
|
// to remind users they are using non-prod setting.
|
||||||
h.Set("X-Gitea-Debug", "RUN_MODE="+setting.RunMode)
|
h.Set("X-Gitea-Debug", "RUN_MODE="+setting.RunMode)
|
||||||
|
h.Set("X-Forgejo-Debug", "RUN_MODE="+setting.RunMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Set("Cache-Control", strings.Join(append(directives, additionalDirectives...), ", "))
|
h.Set("Cache-Control", strings.Join(append(directives, additionalDirectives...), ", "))
|
||||||
|
|
|
@ -29,6 +29,9 @@ func countFormalHeaders(h http.Header) (c int) {
|
||||||
if strings.HasPrefix(k, "X-Gitea-") {
|
if strings.HasPrefix(k, "X-Gitea-") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(k, "X-Forgejo-") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
c++
|
c++
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
|
|
@ -675,7 +675,7 @@ func Routes(ctx gocontext.Context) *web.Route {
|
||||||
// setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
|
// setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
|
||||||
AllowedMethods: setting.CORSConfig.Methods,
|
AllowedMethods: setting.CORSConfig.Methods,
|
||||||
AllowCredentials: setting.CORSConfig.AllowCredentials,
|
AllowCredentials: setting.CORSConfig.AllowCredentials,
|
||||||
AllowedHeaders: append([]string{"Authorization", "X-Gitea-OTP"}, setting.CORSConfig.Headers...),
|
AllowedHeaders: append([]string{"Authorization", "X-Gitea-OTP", "X-Forgejo-OTP"}, setting.CORSConfig.Headers...),
|
||||||
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()),
|
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,10 @@ import (
|
||||||
files_service "code.gitea.io/gitea/services/repository/files"
|
files_service "code.gitea.io/gitea/services/repository/files"
|
||||||
)
|
)
|
||||||
|
|
||||||
const giteaObjectTypeHeader = "X-Gitea-Object-Type"
|
const (
|
||||||
|
giteaObjectTypeHeader = "X-Gitea-Object-Type"
|
||||||
|
forgejoObjectTypeHeader = "X-Forgejo-Object-Type"
|
||||||
|
)
|
||||||
|
|
||||||
// GetRawFile get a file by path on a repository
|
// GetRawFile get a file by path on a repository
|
||||||
func GetRawFile(ctx *context.APIContext) {
|
func GetRawFile(ctx *context.APIContext) {
|
||||||
|
@ -79,6 +82,7 @@ func GetRawFile(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||||
|
ctx.RespHeader().Set(forgejoObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||||
|
|
||||||
if err := common.ServeBlob(ctx.Context, blob, lastModified); err != nil {
|
if err := common.ServeBlob(ctx.Context, blob, lastModified); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ServeBlob", err)
|
ctx.Error(http.StatusInternalServerError, "ServeBlob", err)
|
||||||
|
@ -128,6 +132,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||||
|
ctx.RespHeader().Set(forgejoObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||||
|
|
||||||
// LFS Pointer files are at most 1024 bytes - so any blob greater than 1024 bytes cannot be an LFS file
|
// LFS Pointer files are at most 1024 bytes - so any blob greater than 1024 bytes cannot be an LFS file
|
||||||
if blob.Size() > 1024 {
|
if blob.Size() > 1024 {
|
||||||
|
|
|
@ -415,6 +415,16 @@ func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient
|
||||||
"X-Gitea-Issue-ID": strconv.FormatInt(ctx.Issue.Index, 10),
|
"X-Gitea-Issue-ID": strconv.FormatInt(ctx.Issue.Index, 10),
|
||||||
"X-Gitea-Issue-Link": ctx.Issue.HTMLURL(),
|
"X-Gitea-Issue-Link": ctx.Issue.HTMLURL(),
|
||||||
|
|
||||||
|
"X-Forgejo-Reason": reason,
|
||||||
|
"X-Forgejo-Sender": ctx.Doer.DisplayName(),
|
||||||
|
"X-Forgejo-Recipient": recipient.DisplayName(),
|
||||||
|
"X-Forgejo-Recipient-Address": recipient.Email,
|
||||||
|
"X-Forgejo-Repository": repo.Name,
|
||||||
|
"X-Forgejo-Repository-Path": repo.FullName(),
|
||||||
|
"X-Forgejo-Repository-Link": repo.HTMLURL(),
|
||||||
|
"X-Forgejo-Issue-ID": strconv.FormatInt(ctx.Issue.Index, 10),
|
||||||
|
"X-Forgejo-Issue-Link": ctx.Issue.HTMLURL(),
|
||||||
|
|
||||||
"X-GitHub-Reason": reason,
|
"X-GitHub-Reason": reason,
|
||||||
"X-GitHub-Sender": ctx.Doer.DisplayName(),
|
"X-GitHub-Sender": ctx.Doer.DisplayName(),
|
||||||
"X-GitHub-Recipient": recipient.DisplayName(),
|
"X-GitHub-Recipient": recipient.DisplayName(),
|
||||||
|
|
|
@ -123,6 +123,10 @@ func Deliver(ctx context.Context, t *webhook_model.HookTask) error {
|
||||||
|
|
||||||
event := t.EventType.Event()
|
event := t.EventType.Event()
|
||||||
eventType := string(t.EventType)
|
eventType := string(t.EventType)
|
||||||
|
req.Header.Add("X-Forgejo-Delivery", t.UUID)
|
||||||
|
req.Header.Add("X-Forgejo-Event", event)
|
||||||
|
req.Header.Add("X-Forgejo-Event-Type", eventType)
|
||||||
|
req.Header.Add("X-Forgejo-Signature", signatureSHA256)
|
||||||
req.Header.Add("X-Gitea-Delivery", t.UUID)
|
req.Header.Add("X-Gitea-Delivery", t.UUID)
|
||||||
req.Header.Add("X-Gitea-Event", event)
|
req.Header.Add("X-Gitea-Event", event)
|
||||||
req.Header.Add("X-Gitea-Event-Type", eventType)
|
req.Header.Add("X-Gitea-Event-Type", eventType)
|
||||||
|
|
Loading…
Reference in a new issue