Monorepo for Tangled tangled.org
2

Configure Feed

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

knotmirror/xrpc: fallback to octet-stream on `git.getBlob`

Also set etag for any small contents.

Signed-off-by: Seongmin Lee <git@boltless.me>

author
Seongmin Lee
committer
Tangled
date (Jun 11, 2026, 10:52 AM +0300) commit a6167d9c parent e210539c change-id pnmpvzul
+10 -9
+10 -9
knotmirror/xrpc/git_get_blob.go
··· 73 73 return 74 74 } 75 75 76 + eTag := fmt.Sprintf("\"%x\"", sha256.Sum256(contents)) 77 + if clientETag := r.Header.Get("If-None-Match"); clientETag == eTag { 78 + w.WriteHeader(http.StatusNotModified) 79 + return 80 + } 81 + w.Header().Set("ETag", eTag) 82 + w.Header().Set("X-Content-Type-Options", "nosniff") 83 + 76 84 mimeType := http.DetectContentType(contents) 77 85 // override MIME types for formats that http.DetectContentType does not recognize 78 86 switch filepath.Ext(path) { ··· 88 96 89 97 switch { 90 98 case strings.HasPrefix(mimeType, "image/"), strings.HasPrefix(mimeType, "video/"): 91 - eTag := fmt.Sprintf("\"%x\"", sha256.Sum256(contents)) 92 - if clientETag := r.Header.Get("If-None-Match"); clientETag == eTag { 93 - w.WriteHeader(http.StatusNotModified) 94 - return 95 - } 96 - w.Header().Set("ETag", eTag) 97 99 w.Header().Set("Content-Type", mimeType) 98 100 99 101 case strings.HasPrefix(mimeType, "text/") || isTextualMimeType(mimeType): ··· 102 104 w.Header().Set("Content-Type", "text/plain; charset=utf-8") 103 105 104 106 default: 105 - l.Error("attempted to serve disallowed file type", "mimetype", mimeType) 106 - writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InvalidRequest", Message: "only image, video, and text files can be accessed directly"}) 107 - return 107 + // fallback to octet-stream 108 + w.Header().Set("Content-Type", "application/octet-stream") 108 109 } 109 110 w.Write(contents) 110 111 }