forked from NYANDEV/forgejo
[BRANDING] add X-Forgejo-* headers
(cherry picked from commit 0a3388f93f53f53cce79ebcc194d67979cbe61cc) (cherry picked from commit 7eba0a440a3138443d0b7461560f9f6f1c46b256) (cherry picked from commit eb9646c7ef0b1a9e73bf22806acbc2caeaee7ff3) (cherry picked from commit f1972578f5cb72ad9e1ef1ded9aa324b1d669864) Conflicts: (cherry picked from commit 7f96222fb4b4a773193a11d4ba76f449013c30ef) (cherry picked from commit e3c7c9fe7b5809cdb75f1eb629c82b27986f7e98) (cherry picked from commit 84fdead90242e68493efb96a7fee1e3b5fd417e9) (cherry picked from commit 85148e11961b86269b7cda30294a4cdc817787d0) (cherry picked from commit c0086bd70d39d9a1075fa624cdbfdf5ef26f7a2c) (cherry picked from commit d1e31ef31817e5e811f6bea7aee5582383d53b12) (cherry picked from commit 681d3ed5c43d45f802dc13c58c5b821da938374d) (cherry picked from commit 76a3001f5bc5a064054514c179ba14008952e914) (cherry picked from commit a55a9567d36f6b60557df3df3a0801c0fccec963) (cherry picked from commit aa7adc167d4e4ee7879b88fe799f2afca2fd5531) (cherry picked from commit d5354cb52c26ab0090388d019efe61770e7ec452) (cherry picked from commit 472c48999699420d15aaa7c61a42db8136221616) (cherry picked from commit dc816d065b715f2bfdc7fa68fa2d254f3d481b35) (cherry picked from commit 4795f9ea85eac21c70db1159914a7b7b035b7374) (cherry picked from commit ddd4ae53433d4adab823aa974c0f1c39d0394414) (cherry picked from commit 0e95f2a36b1c0f480f94fef85d341792c7a7b759) (cherry picked from commit 47a41a4e7b3c5d3cf247dafef17a64415069f171) (cherry picked from commit d4416fcd3ee0f1d74c2b03fbe40c15b83f80b56d) (cherry picked from commit f279d153b61677e2a766859c7a7688b0327e7c9a) (cherry picked from commit 959f908ffdc9dd2fb07aefdf7cb85ba34f9071a3) (cherry picked from commit 82df95310176a083abb9eaa51de9e9754d4f72c6) (cherry picked from commit 8f8c9fd9e3deca0af0f087fc44fcd271e8440a7b) (cherry picked from commit d4a0db7706f30a394192c6023072ad5185a7d600) (cherry picked from commit 44594d623942128072bd86a20b5b90603517005e) (cherry picked from commit 62b1de579ebfe326340b218cc9a980b705b8e6a2) (cherry picked from commit 507abee353f120247276fe9165f09976421f926d) (cherry picked from commit 8c36ac42c7091661b2f3fec70fc88a74043628fc) (cherry picked from commit 72f74067f4c781e1c4936f0da2653a35a6f1c82b) (cherry picked from commit 8e5a9e187b50a6eb8523c6dda4ce1a23c08a0b5a) (cherry picked from commit cff8f43c7e4ab86a468ea49f7b945412d9911151) (cherry picked from commit 13544bbde89078aae9dc068b827df82484f813f1) (cherry picked from commit 5b7a11734710f1f8e1cf64b3cc678d7e78747b94) (cherry picked from commit ab61310f1089dea957ccdd7c0c214c3c0033aad9) (cherry picked from commit 537c214c284dd3860450b5082a469dc64b6ec758)
This commit is contained in:
parent
c428c3f14c
commit
91a6c59c9d
6 changed files with 25 additions and 2 deletions
|
@ -30,6 +30,7 @@ func SetCacheControlInHeader(h http.Header, maxAge time.Duration, additionalDire
|
|||
|
||||
// to remind users they are using non-prod setting.
|
||||
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...), ", "))
|
||||
|
|
|
@ -18,6 +18,9 @@ func countFormalHeaders(h http.Header) (c int) {
|
|||
if strings.HasPrefix(k, "X-Gitea-") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(k, "X-Forgejo-") {
|
||||
continue
|
||||
}
|
||||
c++
|
||||
}
|
||||
return c
|
||||
|
|
|
@ -835,7 +835,7 @@ func Routes() *web.Route {
|
|||
// setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
|
||||
AllowedMethods: setting.CORSConfig.Methods,
|
||||
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()),
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -33,7 +33,10 @@ import (
|
|||
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
|
||||
func GetRawFile(ctx *context.APIContext) {
|
||||
|
@ -80,6 +83,7 @@ func GetRawFile(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||
ctx.RespHeader().Set(forgejoObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||
|
||||
if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ServeBlob", err)
|
||||
|
@ -129,6 +133,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
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
|
||||
if blob.Size() > 1024 {
|
||||
|
|
|
@ -399,6 +399,16 @@ func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient
|
|||
"X-Gitea-Issue-ID": strconv.FormatInt(ctx.Issue.Index, 10),
|
||||
"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-Sender": ctx.Doer.DisplayName(),
|
||||
"X-GitHub-Recipient": recipient.DisplayName(),
|
||||
|
|
|
@ -123,6 +123,10 @@ func Deliver(ctx context.Context, t *webhook_model.HookTask) error {
|
|||
|
||||
event := t.EventType.Event()
|
||||
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-Event", event)
|
||||
req.Header.Add("X-Gitea-Event-Type", eventType)
|
||||
|
|
Loading…
Reference in a new issue