@@ -11,6 +11,7 @@ import (
11
11
12
12
"code.gitea.io/gitea/modules/charset"
13
13
"code.gitea.io/gitea/modules/git"
14
+ "code.gitea.io/gitea/modules/log"
14
15
"code.gitea.io/gitea/modules/markup"
15
16
"code.gitea.io/gitea/modules/typesniffer"
16
17
"code.gitea.io/gitea/modules/util"
@@ -44,20 +45,17 @@ func RenderFile(ctx *context.Context) {
44
45
isTextFile := st .IsText ()
45
46
46
47
rd := charset .ToUTF8WithFallbackReader (io .MultiReader (bytes .NewReader (buf ), dataRc ), charset.ConvertOpts {})
48
+ ctx .Resp .Header ().Add ("Content-Security-Policy" , "frame-src 'self'; sandbox allow-scripts" )
47
49
48
50
if markupType := markup .Type (blob .Name ()); markupType == "" {
49
51
if isTextFile {
50
- _ , err = io .Copy (ctx .Resp , rd )
51
- if err != nil {
52
- ctx .ServerError ("Copy" , err )
53
- }
54
- return
52
+ _ , _ = io .Copy (ctx .Resp , rd )
53
+ } else {
54
+ http .Error (ctx .Resp , "Unsupported file type render" , http .StatusInternalServerError )
55
55
}
56
- ctx .Error (http .StatusInternalServerError , "Unsupported file type render" )
57
56
return
58
57
}
59
58
60
- ctx .Resp .Header ().Add ("Content-Security-Policy" , "frame-src 'self'; sandbox allow-scripts" )
61
59
err = markup .Render (& markup.RenderContext {
62
60
Ctx : ctx ,
63
61
RelativePath : ctx .Repo .TreePath ,
@@ -71,7 +69,8 @@ func RenderFile(ctx *context.Context) {
71
69
InStandalonePage : true ,
72
70
}, rd , ctx .Resp )
73
71
if err != nil {
74
- ctx .ServerError ("Render" , err )
72
+ log .Error ("Failed to render file %q: %v" , ctx .Repo .TreePath , err )
73
+ http .Error (ctx .Resp , "Failed to render file" , http .StatusInternalServerError )
75
74
return
76
75
}
77
76
}
0 commit comments