loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor render (#30136)

(cherry picked from commit f1707f4562158853552d57394b8b1fea6df645b0)

authored by

wxiaoguang and committed by
Earl Warren
94515b0d 969df619

+7 -8
+7 -8
routers/web/repo/render.go
··· 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 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 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 }