oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "io"
5 "net/http"
6
7 "amadan.net/oficina/equipo/internal/wire"
8)
9
10// chatDraft renders a reply that is still streaming, as far as it has
11// come, with the renderer the finished message uses (chatmarkdown), so
12// the end of a stream changes nothing but the last characters. The page
13// (chat-stream.js) posts the text it has gathered from the deltas; it is
14// rendered and sent back, from this origin only, and nothing is kept.
15func (a *application) chatDraft(w http.ResponseWriter, r *http.Request) {
16 w.Header().Set("Cache-Control", "no-store")
17 if _, _, ok := sessionContext(r); !ok || r.Header.Get("Sec-Fetch-Site") != "same-origin" {
18 a.failure(w, r, ErrForbidden)
19 return
20 }
21 // A reply is kept to 4*MaxMessageBytes (chat.reply); the form
22 // encoding may triple it.
23 r.Body = http.MaxBytesReader(w, r.Body, 12*wire.MaxMessageBytes+64)
24 if err := r.ParseForm(); err != nil {
25 a.failure(w, r, ErrInvalid)
26 return
27 }
28 text := r.PostForm.Get("text")
29 if len(text) > 4*wire.MaxMessageBytes {
30 text = text[:4*wire.MaxMessageBytes]
31 }
32 w.Header().Set("Content-Type", "text/html; charset=utf-8")
33 _, _ = io.WriteString(w, string(pasteBox.RenderDraft(text)))
34}
35