Skip to content

Commit

Permalink
Merge branch 'main' into fedtest2
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Feb 9, 2025
2 parents 583db1f + 267dc42 commit 04813d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion front/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ func (h *Handler) Handle(r *Request, w text.Writer) {

r.Log.Warn("Received an invalid request")

if r.User == nil {
if r.URL.Scheme == "titan" && r.User == nil {
w.Redirectf("gemini://%s/oops", h.Domain)
} else if r.URL.Scheme == "titan" && r.User != nil {
w.Redirectf("gemini://%s/users/oops", h.Domain)
} else if r.User == nil {
w.Redirect("/oops")
} else {
w.Redirect("/users/oops")
Expand Down
21 changes: 17 additions & 4 deletions front/text/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func LineBuffered(inner io.Writer) *LineWriter {
t := time.NewTicker(flushInterval)
defer t.Stop()

drain := func() {
for {
select {
case <-t.C:
default:
return
}
}
}

loop:
for {
select {
Expand All @@ -73,6 +83,7 @@ func LineBuffered(inner io.Writer) *LineWriter {
if i == -1 {
w.buffer.Write(buf)
t.Stop()
drain()
break
}

Expand All @@ -81,15 +92,16 @@ func LineBuffered(inner io.Writer) *LineWriter {

// flush if we have $bufferSize lines in the buffer
if lines == bufferSize {
t.Stop()
drain()

if _, err := w.inner.Write(w.buffer.Bytes()); err != nil {
w.stop(err)
return
}

w.buffer.Reset()
lines = 0

t.Stop()
} else if lines > 0 {
t.Reset(flushInterval)
}
Expand All @@ -105,15 +117,16 @@ func LineBuffered(inner io.Writer) *LineWriter {
continue
}

t.Stop()
drain()

if _, err := w.inner.Write(buf); err != nil {
w.stop(err)
return
}

w.buffer.Reset()
lines = 0

t.Stop()
}
}

Expand Down

0 comments on commit 04813d9

Please sign in to comment.