gunk-dev/the-valley

server.go

source9d44ba98f6b9main's published tip history
23.6 KiB
1// Package server is the web UI's read side. It serves the active export
2// of a receiver's state directory to anonymous readers: the plan page,
3// each knot, and a source browser over each public project's main.
4//
5// # Snapshots
6//
7// Every request opens the store's active generation once, with
8// export.Store.Open, and renders its whole response from that
9// generation. An activation during the request changes nothing the
10// request reads. The server keeps a snapshot of the newest generation it
11// has read: the export, decoded, and its index. A request opens its
12// generation only once the generation has a snapshot, and every request
13// for that generation serves from the one snapshot.
14//
15// A request whose generation has no snapshot yet waits for a load. A load
16// runs in a worker of its own, which opens the active generation, holds
17// it while it reads and indexes the export, and then gives it back. At
18// most MaxLoads workers run at once. The requests that wait for a
19// generation share one load, so each export is read once. A waiting
20// request holds no generation, and stops waiting when its reader goes away
21// or its time runs out. A load stops once no request waits for it, and
22// the server keeps nothing of what it read.
23//
24// # Admission
25//
26// Every request's time is bounded from when it arrives: its waits, its
27// git commands and its rendering. A source request runs git, and at most
28// MaxGit run at once. A source request takes one of those slots before
29// it opens a generation, and waits for one only while fewer than
30// MaxWaiting wait. A request waits for a load only while fewer than
31// MaxLoadWaiting wait, and it is admitted among them before it opens
32// anything. A request the server cannot admit, or that runs out of time,
33// answers 503.
34//
35// # Responses
36//
37// A response is rendered whole before it is written. A request gives back
38// its generation and its git slot before it writes, so a reader that
39// reads slowly holds neither. It keeps its response until the response
40// is written.
41//
42// A response's body is at most MaxResponse bytes. A page that would pass
43// it stops rendering there, and the request answers with a short page
44// that says the page is too large. Rendered responses take their memory
45// from a budget of MaxBuffered bytes, which they give back once they are
46// written. A request that finds the budget spent answers 503.
47//
48// # Routes
49//
50// The server answers GET and HEAD alone:
51//
52// / the plan page
53// /<project>/ a redirect to the tree at main's tip
54// /<project>/knots/<id> one knot, with its body and comments
55// /<project>/source/ a redirect to the tree at main's tip
56// /<project>/source/tree/<commit>/<path> a directory and its README
57// /<project>/source/blob/<commit>/<path> a file
58// /<project>/source/log/<commit> the history that ends at a commit
59// /-/... the server's own paths
60//
61// Every path but / and those under /-/ starts with a project's name. No
62// project name starts with "-", so no project's path is ever one of the
63// server's own, whatever paths the server adds there. It serves no page
64// under /-/, and answers each path there with the one 404.
65//
66// Every source link names its project, a full commit ID and a path. A
67// commit is served only when export.Reachable finds it reachable from the
68// project's published source tip, and a path is resolved one tree entry
69// at a time from that commit's tree, so no other object can be named.
70//
71// # Access
72//
73// Every route checks that the export holds its project as public. A
74// project it does not hold answers exactly as a project that does not
75// exist: every 404 is the same page.
76//
77// # Safety
78//
79// Every page is rendered on the server with html/template, so everything
80// read from the export or a repository is escaped. Each response carries
81// a strict Content-Security-Policy: default-src 'self', and one inline
82// stylesheet and one inline script admitted by their SHA-256 hashes. No
83// repository file is served as itself: a file is shown as escaped text,
84// and a binary file or one larger than MaxFile is not shown at all.
85package server
86
87import (
88 "bytes"
89 "context"
90 "errors"
91 "fmt"
92 "io"
93 "log"
94 "net/http"
95 "net/url"
96 "os"
97 "strconv"
98 "strings"
99 "sync"
100 "syscall"
101 "time"
102
103 "the-valley/webui/export"
104)
105
106// StaleAfter is how old an export may be before its pages mark it stale.
107const StaleAfter = 5 * time.Minute
108
109// The bounds on what one request reads from a repository.
110const (
111 // MaxFile is the largest file a page shows, README or otherwise.
112 MaxFile = 1 << 20
113 // MaxLines is the most lines of a file a page shows.
114 MaxLines = 10_000
115 // MaxShown is the most bytes a page spends on a file's text once it
116 // is escaped, counting each line's markup on a file page. A page
117 // stops at the line that would take it past MaxShown.
118 MaxShown = 2 << 20
119 // MaxEntries is the most entries a directory page lists.
120 MaxEntries = 1000
121 // MaxRead is the most bytes of output a page reads from one git
122 // listing: a directory's entries, or a page of history. git is
123 // stopped once it prints more.
124 MaxRead = 4 << 20
125 // MaxDepth is the most path segments a source route takes.
126 MaxDepth = 64
127 // MaxPlanDepth is the most levels of knots a milestone's tree
128 // shows, and the most parents a knot's trail names.
129 MaxPlanDepth = 32
130 // LogPage is the number of commits on one page of a log.
131 LogPage = 50
132 // MaxGit is the most source requests that run git at once.
133 MaxGit = 8
134 // MaxWaiting is the most source requests that wait for one of the
135 // MaxGit to finish. A source request that finds every slot taken
136 // and MaxWaiting waiting answers 503 at once.
137 MaxWaiting = 16
138 // requestTimeout bounds a request from when it arrives: its wait for
139 // a git slot or for its generation's export to be read, its git
140 // commands and its rendering.
141 requestTimeout = 15 * time.Second
142 // MaxLoads is the most loads that run at once, each in a worker of
143 // its own that reads one generation's export.
144 MaxLoads = 2
145 // MaxLoadWaiting is the most requests that wait for loads. A request
146 // that would wait while MaxLoadWaiting do answers 503 at once.
147 MaxLoadWaiting = 64
148 // MaxResponse is the most bytes a response's body takes. A page
149 // that would take more stops rendering, and the request answers with
150 // a short page that says the page is too large.
151 MaxResponse = 8 << 20
152 // MaxBuffered is the most bytes of rendered responses the server
153 // holds at once, from when each starts rendering until it is
154 // written. A response takes them in pieces of pieceSize as it
155 // renders.
156 MaxBuffered = 64 << 20
157 // pieceSize is the size of the pieces a response is rendered into.
158 pieceSize = 64 << 10
159)
160
161// Config is what a Server serves from.
162type Config struct {
163 // Store is the receiver's state directory.
164 Store *export.Store
165 // Now is the clock an export's age is read against. Nil is time.Now.
166 Now func() time.Time
167 // Log is told of each failure a reader sees only as an error page.
168 // Nil logs with the standard logger.
169 Log func(error)
170}
171
172// Server is the read side's HTTP handler.
173type Server struct {
174 store *export.Store
175 now func() time.Time
176 log func(error)
177 // timeout is requestTimeout, and maxResponse is MaxResponse. A test
178 // shortens either.
179 timeout time.Duration
180 maxResponse int
181 // slots holds a token for each source request running git, and
182 // waiting one for each source request waiting for a slot.
183 slots chan struct{}
184 waiting chan struct{}
185 // loaders holds a token for each load's worker, and loadWaiting one
186 // for each request waiting for a load.
187 loaders chan struct{}
188 loadWaiting chan struct{}
189 // budget holds a token for each piece of a response that is being
190 // rendered or written: MaxBuffered bytes, in pieces of pieceSize.
191 budget chan struct{}
192
193 mu sync.Mutex
194 // cached is the newest generation's snapshot read so far.
195 cached *snapshot
196 // loads are the loads a request that waits may still join: those that
197 // have not ended, and that some request waits for.
198 loads map[*load]struct{}
199
200 // The test hooks. opened, when set, is called with each generation a
201 // request opens, before the request reads anything from it. admitted
202 // is called when a source request takes a git slot, before it opens
203 // a generation. loading is called by a load's worker with the
204 // generation it opened, before it reads the generation's export.
205 opened func(export.Generation)
206 admitted func()
207 loading func(export.Generation)
208}
209
210// New is a Server over c's store.
211func New(c Config) *Server {
212 s := &Server{store: c.Store, now: c.Now, log: c.Log, timeout: requestTimeout, maxResponse: MaxResponse,
213 slots: make(chan struct{}, MaxGit), waiting: make(chan struct{}, MaxWaiting),
214 loaders: make(chan struct{}, MaxLoads), loadWaiting: make(chan struct{}, MaxLoadWaiting),
215 budget: make(chan struct{}, MaxBuffered/pieceSize), loads: map[*load]struct{}{}}
216 if s.now == nil {
217 s.now = time.Now
218 }
219 if s.log == nil {
220 s.log = func(err error) { log.Print(err) }
221 }
222 return s
223}
224
225// snapshot is one generation's export, decoded, and its index. A
226// generation is immutable once active, and its sequence names it, so a
227// snapshot serves every request that opens its generation.
228type snapshot struct {
229 seq int64
230 e *export.Export
231 idx *index
232}
233
234// load reads the active generation's export for every request that
235// waits for it. It starts once one of those requests takes a loader slot
236// for it, and runs in a worker of its own, so a request can stop waiting
237// while the load goes on for the others.
238type load struct {
239 // wants counts the requests that wait for the load. cancel is set once
240 // the load has started, and stops its worker. The worker sets opened
241 // and seq once it has opened a generation. All are guarded by the
242 // server's mu.
243 wants int
244 cancel context.CancelFunc
245 opened bool
246 seq int64
247 // started is closed once the load starts, and done once its worker
248 // ends. err is the worker's error, set before done is closed.
249 started chan struct{}
250 done chan struct{}
251 err error
252}
253
254// request is one request, the generation it serves from, and the
255// response it renders.
256type request struct {
257 s *Server
258 w http.ResponseWriter
259 r *http.Request
260 // ctx is the context the request waits and runs git under. It ends
261 // at the request's deadline, or when its reader goes away.
262 ctx context.Context
263 g export.Generation
264 e *export.Export
265 idx *index
266 now time.Time
267
268 // The response: a status and a page, or a redirect. It is written
269 // once the request has given back its generation and git slot, and
270 // the page's pieces are given back to the budget once it is written.
271 status int
272 ctype string
273 body *body
274 location string
275}
276
277func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
278 setHeaders(w.Header())
279 ctx, cancel := context.WithTimeout(r.Context(), s.timeout)
280 defer cancel()
281 q := &request{s: s, w: w, r: r, ctx: ctx, now: s.now()}
282 defer q.drop()
283 q.serve()
284 q.write()
285}
286
287// serve renders the request's response. A source request is admitted
288// first, and holds its git slot until serve returns. Every request holds
289// its generation until serve returns.
290func (q *request) serve() {
291 if q.r.Method != http.MethodGet && q.r.Method != http.MethodHead {
292 q.w.Header().Set("Allow", "GET, HEAD")
293 q.page(http.StatusMethodNotAllowed, "error", "Method not allowed", errorPage{
294 Heading: "Method not allowed", Text: "This server answers GET and HEAD alone.",
295 })
296 return
297 }
298 parts, ok := segments(q.r.URL.EscapedPath())
299 if ok && runsGit(parts) {
300 done, admitted := q.s.admit(q.ctx)
301 if !admitted {
302 q.busy()
303 return
304 }
305 defer done()
306 if q.s.admitted != nil {
307 q.s.admitted()
308 }
309 }
310 g, snap, release, err := q.s.open(q.ctx)
311 defer release()
312 switch {
313 case errors.Is(err, export.ErrNoExport):
314 q.page(http.StatusServiceUnavailable, "error", "Nothing published", errorPage{
315 Heading: "Nothing published yet", Text: "No export has been activated on this server.",
316 })
317 return
318 case errors.Is(err, errLoadsFull):
319 q.busy()
320 return
321 case err != nil:
322 q.fail(err)
323 return
324 }
325 if q.s.opened != nil {
326 q.s.opened(g)
327 }
328 q.g, q.e, q.idx = g, snap.e, snap.idx
329 q.route(parts, ok)
330}
331
332// runsGit reports whether a path is a source route that reads a
333// repository: a tree, a file or a log of something that may be a project.
334func runsGit(parts []string) bool {
335 return len(parts) >= 3 && export.ValidName(parts[0]) && parts[1] == "source" &&
336 (parts[2] == "tree" || parts[2] == "blob" || parts[2] == "log")
337}
338
339// admit takes a git slot for a source request. When every slot is taken,
340// it waits for one until ctx is done, unless MaxWaiting requests wait
341// already. done gives the slot back.
342func (s *Server) admit(ctx context.Context) (done func(), ok bool) {
343 give := func() { <-s.slots }
344 select {
345 case s.slots <- struct{}{}:
346 return give, true
347 default:
348 }
349 select {
350 case s.waiting <- struct{}{}:
351 default:
352 return nil, false
353 }
354 defer func() { <-s.waiting }()
355 select {
356 case s.slots <- struct{}{}:
357 return give, true
358 case <-ctx.Done():
359 return nil, false
360 }
361}
362
363// errLoadsFull is open's error for a request that would wait for a load
364// while MaxLoadWaiting requests wait already.
365var errLoadsFull = errors.New("too many requests wait for exports to be read")
366
367// open opens the active generation once its snapshot is cached, and
368// returns both. release gives the generation back.
369//
370// A request whose active generation has no snapshot waits for a load,
371// and opens nothing until the load ends. It is admitted among the
372// MaxLoadWaiting requests that may wait before it waits, and it keeps its
373// place until open returns. Once the load ends it looks again, since
374// another generation may have been activated meanwhile.
375func (s *Server) open(ctx context.Context) (g export.Generation, snap *snapshot, release func(), err error) {
376 release = func() {}
377 waiting := false
378 defer func() {
379 if waiting {
380 <-s.loadWaiting
381 }
382 }()
383 for {
384 seq, err := s.store.Active()
385 if err != nil {
386 return g, nil, release, err
387 }
388 s.mu.Lock()
389 snap = s.cached
390 s.mu.Unlock()
391 if snap != nil && snap.seq == seq {
392 g, release, err = s.store.Open()
393 if err != nil || g.Sequence == seq {
394 return g, snap, release, err
395 }
396 release() // active moved on since it was read
397 release = func() {}
398 continue
399 }
400 if !waiting {
401 select {
402 case s.loadWaiting <- struct{}{}:
403 waiting = true
404 default:
405 return g, nil, release, errLoadsFull
406 }
407 }
408 if err := s.await(ctx, seq); err != nil {
409 return g, nil, release, err
410 }
411 }
412}
413
414// await waits until a load of generation seq, or of a newer one, ends,
415// or until ctx is done. It joins a load that will read seq or a newer
416// generation, since a worker reads whatever generation is active once it
417// starts, and otherwise makes one.
418//
419// A load starts only once one of its requests takes a loader slot for
420// it. While every slot is taken, each of its requests waits for one, and
421// the first to take one starts the load, so no load is queued that no
422// request waits for. A request that stops waiting leaves the load, and
423// the last to leave stops it.
424func (s *Server) await(ctx context.Context, seq int64) error {
425 s.mu.Lock()
426 if c := s.cached; c != nil && c.seq >= seq {
427 s.mu.Unlock()
428 return nil
429 }
430 var l *load
431 for m := range s.loads {
432 if !m.opened || m.seq >= seq {
433 l = m
434 break
435 }
436 }
437 if l == nil {
438 l = &load{started: make(chan struct{}), done: make(chan struct{})}
439 s.loads[l] = struct{}{}
440 }
441 l.wants++
442 s.mu.Unlock()
443 select {
444 case <-l.started:
445 case s.loaders <- struct{}{}:
446 if !s.start(l) {
447 <-s.loaders
448 }
449 case <-ctx.Done():
450 s.leave(l)
451 return fmt.Errorf("waiting for generation %d's export to be read: %w", seq, ctx.Err())
452 }
453 select {
454 case <-l.done:
455 return l.err
456 case <-ctx.Done():
457 s.leave(l)
458 return fmt.Errorf("waiting for generation %d's export to be read: %w", seq, ctx.Err())
459 }
460}
461
462// start starts l's worker, for the request that took a loader slot for
463// it. It is false when another request started it already.
464func (s *Server) start(l *load) bool {
465 s.mu.Lock()
466 defer s.mu.Unlock()
467 if l.cancel != nil {
468 return false
469 }
470 ctx, cancel := context.WithCancel(context.Background())
471 l.cancel = cancel
472 close(l.started)
473 go s.run(ctx, l)
474 return true
475}
476
477// leave is a request that stopped waiting for l. Once no request waits for
478// it, no request may join it, and a load that started is stopped.
479func (s *Server) leave(l *load) {
480 s.mu.Lock()
481 defer s.mu.Unlock()
482 if l.wants--; l.wants > 0 {
483 return
484 }
485 delete(s.loads, l)
486 if l.cancel != nil {
487 l.cancel()
488 }
489}
490
491// run is l's worker. It caches the snapshot it reads when the snapshot's
492// generation is newer than the cached one's, so a load of an older
493// generation never displaces a newer. A load that was stopped caches
494// nothing: leave stops it under mu, and run looks under mu. The worker
495// gives back its generation before it ends, and then its loader slot.
496func (s *Server) run(ctx context.Context, l *load) {
497 snap, err := s.read(ctx, l)
498 s.mu.Lock()
499 delete(s.loads, l)
500 if snap != nil && ctx.Err() == nil && (s.cached == nil || s.cached.seq < snap.seq) {
501 s.cached = snap
502 }
503 l.err = err
504 s.mu.Unlock()
505 l.cancel()
506 close(l.done)
507 <-s.loaders
508}
509
510// read opens the active generation for l, and holds it while it reads
511// and indexes the generation's export. It reads nothing when the
512// generation is cached already or another load reads it, and its waiting
513// requests look again. It stops reading once ctx is done.
514func (s *Server) read(ctx context.Context, l *load) (snap *snapshot, err error) {
515 // Cancellation can close the file during any operation. Report the
516 // context error instead of the resulting descriptor error.
517 defer func() {
518 if stopped := ctx.Err(); stopped != nil {
519 snap, err = nil, stopped
520 }
521 }()
522 if err := ctx.Err(); err != nil {
523 return nil, err
524 }
525 g, release, err := s.store.Open()
526 if err != nil {
527 return nil, err
528 }
529 defer release()
530 s.mu.Lock()
531 read := s.cached == nil || s.cached.seq < g.Sequence
532 for m := range s.loads {
533 if m != l && m.opened && m.seq == g.Sequence {
534 read = false
535 }
536 }
537 l.opened, l.seq = true, g.Sequence
538 s.mu.Unlock()
539 if !read {
540 return nil, nil
541 }
542 if s.loading != nil {
543 s.loading(g)
544 }
545 f, err := os.OpenFile(g.ExportPath(), os.O_RDONLY|syscall.O_NONBLOCK, 0)
546 if err != nil {
547 return nil, err
548 }
549 defer f.Close()
550 // Nonblocking open avoids waiting for a FIFO writer. Go's file poller
551 // waits for reads, and Close wakes a read when the last waiter leaves.
552 stop := context.AfterFunc(ctx, func() { _ = f.Close() })
553 defer stop()
554 info, err := f.Stat()
555 if err != nil {
556 return nil, err
557 }
558 data, err := io.ReadAll(&contextReader{ctx: ctx, r: f, waitForData: info.Mode()&os.ModeNamedPipe != 0})
559 if ctx.Err() != nil {
560 return nil, ctx.Err()
561 }
562 if err != nil {
563 return nil, fmt.Errorf("reading generation %d's export: %w", g.Sequence, err)
564 }
565 e, err := export.DecodeContext(ctx, bytes.NewReader(data))
566 if err != nil {
567 return nil, err
568 }
569 if err := ctx.Err(); err != nil {
570 return nil, err
571 }
572 idx, err := newIndex(ctx, e)
573 if err != nil {
574 return nil, err
575 }
576 return &snapshot{seq: g.Sequence, e: e, idx: idx}, nil
577}
578
579// contextReader reads from r until ctx is done.
580type contextReader struct {
581 ctx context.Context
582 r io.Reader
583 waitForData bool
584}
585
586func (c *contextReader) Read(p []byte) (int, error) {
587 for {
588 if err := c.ctx.Err(); err != nil {
589 return 0, err
590 }
591 n, err := c.r.Read(p)
592 if n > 0 {
593 c.waitForData = false
594 }
595 if !c.waitForData || err != io.EOF {
596 return n, err
597 }
598 // A nonblocking FIFO reports EOF before its first writer arrives.
599 // Wait for that writer without holding a blocking open syscall.
600 timer := time.NewTimer(10 * time.Millisecond)
601 select {
602 case <-c.ctx.Done():
603 timer.Stop()
604 return 0, c.ctx.Err()
605 case <-timer.C:
606 }
607 }
608}
609
610// route dispatches on the path's segments, each unescaped on its own, so
611// an escaped slash stays inside its segment. ok is false for a path whose
612// segments do not unescape.
613func (q *request) route(parts []string, ok bool) {
614 switch {
615 case !ok:
616 q.notFound()
617 case len(parts) == 1 && parts[0] == "":
618 q.plan()
619 case parts[0] == own:
620 q.notFound()
621 case len(parts) == 1, len(parts) == 2 && parts[1] == "":
622 q.home(parts[0])
623 case len(parts) == 3 && parts[1] == "knots":
624 q.knot(parts[0], parts[2])
625 case len(parts) >= 2 && parts[1] == "source":
626 q.source(parts[0], parts[2:])
627 default:
628 q.notFound()
629 }
630}
631
632// own is the first segment of the server's own paths, /-/. No project's
633// name can be it, or start with it.
634const own = "-"
635
636// home answers /<project>/, and /<project>, with a redirect to the
637// project's page: the tree at its published tip, with its README.
638func (q *request) home(project string) {
639 p, ok := q.project(project)
640 if !ok {
641 q.notFound()
642 return
643 }
644 q.redirect(treeURL(p.Name, p.SourceTip, nil))
645}
646
647func segments(escaped string) ([]string, bool) {
648 rest, ok := strings.CutPrefix(escaped, "/")
649 if !ok {
650 return nil, false
651 }
652 parts := strings.Split(rest, "/")
653 for i, p := range parts {
654 u, err := url.PathUnescape(p)
655 if err != nil {
656 return nil, false
657 }
658 parts[i] = u
659 }
660 return parts, true
661}
662
663// project is the export's project called name, when the export holds it
664// as public. Every route that names a project asks here first, and a
665// project it refuses answers as one that does not exist.
666func (q *request) project(name string) (*export.Project, bool) { return q.idx.project(name) }
667
668func (idx *index) project(name string) (*export.Project, bool) {
669 p, ok := idx.projects[name]
670 if !ok || p.Visibility != export.Public {
671 return nil, false
672 }
673 return p, true
674}
675
676// notFound is the one 404 page, whatever was not found. It names nothing
677// of the request, so a hidden project, a missing one, an unreachable
678// commit and a missing path all answer alike.
679func (q *request) notFound() {
680 q.page(http.StatusNotFound, "error", "Not found", errorPage{
681 Heading: "Not found", Text: "Nothing is published at this address.",
682 })
683}
684
685// fail logs err and answers with the one 500 page, which says nothing of
686// the failure. A reader that went away is answered with nothing: git
687// killed for it fails, and that is no failure of the server's. A request
688// that ran out of time answers 503.
689func (q *request) fail(err error) {
690 if q.r.Context().Err() != nil {
691 return
692 }
693 q.s.log(err)
694 if q.ctx.Err() != nil {
695 q.busy()
696 return
697 }
698 q.page(http.StatusInternalServerError, "error", "Error", errorPage{
699 Heading: "Something went wrong", Text: "The server could not read this page.",
700 })
701}
702
703// busy answers a request the server has no room for: a source request it
704// could not admit, a request that ran out of time, or a page the response
705// budget has no room for. A reader that went away is answered with
706// nothing.
707func (q *request) busy() {
708 if q.r.Context().Err() != nil {
709 return
710 }
711 q.w.Header().Set("Retry-After", "5")
712 q.static(http.StatusServiceUnavailable, htmlType, busyPage)
713}
714
715// redirect answers with a redirect to url.
716func (q *request) redirect(url string) { q.location = url }
717
718// write writes the rendered response, or nothing for a reader that went
719// away. It returns once the response is written, or the connection
720// failed or timed out.
721func (q *request) write() {
722 switch {
723 case q.location != "":
724 http.Redirect(q.w, q.r, q.location, http.StatusFound)
725 case q.status != 0:
726 h := q.w.Header()
727 h.Set("Content-Type", q.ctype)
728 h.Set("Content-Length", strconv.Itoa(q.body.n))
729 q.w.WriteHeader(q.status)
730 for _, p := range q.body.pieces {
731 if _, err := q.w.Write(p); err != nil {
732 return
733 }
734 }
735 }
736}
737
738// setHeaders sets the headers every response carries.
739func setHeaders(h http.Header) {
740 h.Set("Content-Security-Policy", csp)
741 h.Set("X-Content-Type-Options", "nosniff")
742 h.Set("X-Frame-Options", "DENY")
743 h.Set("Referrer-Policy", "no-referrer")
744 h.Set("Cross-Origin-Opener-Policy", "same-origin")
745 h.Set("Cross-Origin-Resource-Policy", "same-origin")
746 h.Set("Cache-Control", "no-cache")
747}