[mirror] Scalable static site server for Git forges (like GitHub Pages)

Don't send COEP/COOP headers for non-HTML resources.

miyuko ffedc45a d6a7a72e

Changed files
+14 -10
src
+8 -10
src/pages.go
··· 8 8 "fmt" 9 9 "io" 10 10 "log" 11 - "mime" 12 11 "net/http" 13 12 "net/url" 14 13 "os" ··· 282 281 w.Header().Set("Content-Type", *entry.ContentType) 283 282 } 284 283 285 - // allow the use of multi-threading in WebAssembly 286 - w.Header().Set("Cross-Origin-Embedder-Policy", "credentialless") 287 - w.Header().Set("Cross-Origin-Opener-Policy", "same-origin") 284 + contentType := getMediaType(entry.GetContentType()) 285 + if contentType == "" || contentType == "text/html" || contentType == "application/xhtml+xml" { 286 + // allow the use of multi-threading in WebAssembly 287 + w.Header().Set("Cross-Origin-Embedder-Policy", "credentialless") 288 + w.Header().Set("Cross-Origin-Opener-Policy", "same-origin") 289 + } 288 290 289 291 // consider content fresh for 60 seconds (the same as the freshness interval of 290 292 // manifests in the S3 backend), and use stale content anyway as long as it's not ··· 315 317 316 318 webRoot := makeWebRoot(host, projectName) 317 319 318 - contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) 319 - if err != nil { 320 - http.Error(w, "malformed content type", http.StatusUnsupportedMediaType) 321 - return fmt.Errorf("content type: %w", err) 322 - } 323 - 324 320 updateCtx, cancel := context.WithTimeout(r.Context(), time.Duration(config.Limits.UpdateTimeout)) 325 321 defer cancel() 322 + 323 + contentType := getMediaType(r.Header.Get("Content-Type")) 326 324 327 325 if contentType == "application/x-www-form-urlencoded" { 328 326 auth, err := AuthorizeUpdateFromRepository(r)
+6
src/util.go
··· 79 79 func (e *prettyJoinError) Unwrap() []error { 80 80 return e.errs 81 81 } 82 + 83 + func getMediaType(mimeType string) (mediaType string) { 84 + mediaType, _, _ = strings.Cut(mimeType, ";") 85 + mediaType = strings.TrimSpace(strings.ToLower(mediaType)) 86 + return 87 + }