@@ -33,6 +33,8 @@ import (
33
33
files_service "code.gitea.io/gitea/services/repository/files"
34
34
)
35
35
36
+ const giteaObjectTypeHeader = "X-Gitea-Object-Type"
37
+
36
38
// GetRawFile get a file by path on a repository
37
39
func GetRawFile (ctx * context.APIContext ) {
38
40
// swagger:operation GET /repos/{owner}/{repo}/raw/{filepath} repository repoGetRawFile
@@ -72,11 +74,13 @@ func GetRawFile(ctx *context.APIContext) {
72
74
return
73
75
}
74
76
75
- blob , lastModified := getBlobForEntry (ctx )
77
+ blob , entry , lastModified := getBlobForEntry (ctx )
76
78
if ctx .Written () {
77
79
return
78
80
}
79
81
82
+ ctx .RespHeader ().Set (giteaObjectTypeHeader , string (files_service .GetObjectTypeFromTreeEntry (entry )))
83
+
80
84
if err := common .ServeBlob (ctx .Context , blob , lastModified ); err != nil {
81
85
ctx .Error (http .StatusInternalServerError , "ServeBlob" , err )
82
86
}
@@ -119,11 +123,13 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
119
123
return
120
124
}
121
125
122
- blob , lastModified := getBlobForEntry (ctx )
126
+ blob , entry , lastModified := getBlobForEntry (ctx )
123
127
if ctx .Written () {
124
128
return
125
129
}
126
130
131
+ ctx .RespHeader ().Set (giteaObjectTypeHeader , string (files_service .GetObjectTypeFromTreeEntry (entry )))
132
+
127
133
// LFS Pointer files are at most 1024 bytes - so any blob greater than 1024 bytes cannot be an LFS file
128
134
if blob .Size () > 1024 {
129
135
// First handle caching for the blob
@@ -218,7 +224,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
218
224
}
219
225
}
220
226
221
- func getBlobForEntry (ctx * context.APIContext ) (blob * git.Blob , lastModified time.Time ) {
227
+ func getBlobForEntry (ctx * context.APIContext ) (blob * git.Blob , entry * git. TreeEntry , lastModified time.Time ) {
222
228
entry , err := ctx .Repo .Commit .GetTreeEntryByPath (ctx .Repo .TreePath )
223
229
if err != nil {
224
230
if git .IsErrNotExist (err ) {
@@ -251,7 +257,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, lastModified time
251
257
}
252
258
blob = entry .Blob ()
253
259
254
- return blob , lastModified
260
+ return blob , entry , lastModified
255
261
}
256
262
257
263
// GetArchive get archive of a repository
0 commit comments