@@ -33,6 +33,8 @@ import (
3333 files_service "code.gitea.io/gitea/services/repository/files"
3434)
3535
36+ const giteaObjectTypeHeader = "X-Gitea-Object-Type"
37+
3638// GetRawFile get a file by path on a repository
3739func GetRawFile (ctx * context.APIContext ) {
3840 // swagger:operation GET /repos/{owner}/{repo}/raw/{filepath} repository repoGetRawFile
@@ -72,11 +74,13 @@ func GetRawFile(ctx *context.APIContext) {
7274 return
7375 }
7476
75- blob , lastModified := getBlobForEntry (ctx )
77+ blob , entry , lastModified := getBlobForEntry (ctx )
7678 if ctx .Written () {
7779 return
7880 }
7981
82+ ctx .RespHeader ().Set (giteaObjectTypeHeader , string (files_service .GetObjectTypeFromTreeEntry (entry )))
83+
8084 if err := common .ServeBlob (ctx .Context , blob , lastModified ); err != nil {
8185 ctx .Error (http .StatusInternalServerError , "ServeBlob" , err )
8286 }
@@ -119,11 +123,13 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
119123 return
120124 }
121125
122- blob , lastModified := getBlobForEntry (ctx )
126+ blob , entry , lastModified := getBlobForEntry (ctx )
123127 if ctx .Written () {
124128 return
125129 }
126130
131+ ctx .RespHeader ().Set (giteaObjectTypeHeader , string (files_service .GetObjectTypeFromTreeEntry (entry )))
132+
127133 // LFS Pointer files are at most 1024 bytes - so any blob greater than 1024 bytes cannot be an LFS file
128134 if blob .Size () > 1024 {
129135 // First handle caching for the blob
@@ -218,7 +224,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
218224 }
219225}
220226
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 ) {
222228 entry , err := ctx .Repo .Commit .GetTreeEntryByPath (ctx .Repo .TreePath )
223229 if err != nil {
224230 if git .IsErrNotExist (err ) {
@@ -251,7 +257,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, lastModified time
251257 }
252258 blob = entry .Blob ()
253259
254- return blob , lastModified
260+ return blob , entry , lastModified
255261}
256262
257263// GetArchive get archive of a repository
0 commit comments