cmd/pkgserver: expose size and store pre-encoded ident

This change also handles SIGSEGV correctly in newStatusHandler, and makes serving status fully zero copy.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-11 03:32:09 +09:00
parent fb36c54025
commit 5e114f3932
2 changed files with 24 additions and 16 deletions

View File

@@ -1,9 +1,7 @@
package main
import (
"bytes"
"encoding/json"
"io"
"log"
"net/http"
"path"
@@ -11,7 +9,6 @@ import (
"sync"
"hakurei.app/internal/info"
"hakurei.app/internal/pkg"
"hakurei.app/internal/rosa"
)
@@ -50,19 +47,27 @@ func (index *packageIndex) newStatusHandler(disposition bool) http.HandlerFunc {
if disposition {
contentType = "application/octet-stream"
// quoting like this is unsound, but okay, because metadata is hardcoded
contentDisposition := `attachment; filename="`
contentDisposition += m.Name + "-"
if m.Version != "" {
contentDisposition += m.Version + "-"
}
contentDisposition += pkg.Encode(m.ident.Value()) + `.log"`
contentDisposition += m.ids + `.log"`
w.Header().Set("Content-Disposition", contentDisposition)
}
w.Header().Set("Content-Type", contentType)
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
_, err := io.Copy(w, bytes.NewReader(m.status))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
if err := func() (err error) {
defer index.handleAccess(&err)()
_, err = w.Write(m.status)
return
}(); err != nil {
log.Println(err)
http.Error(
w, "cannot deliver status, contact maintainers",
http.StatusInternalServerError,
)
}
}
}