Skip to content

Commit

Permalink
sumdb: make data tiles by Server compatible with sum.golang.org
Browse files Browse the repository at this point in the history
Make the format of sumdb.Server data tile responses compatible with those
served by sum.golang.org: Like formatted records for the lookup endpoint, but
without each record IDs.

Updates documentation for sumdb/tlog.FormatRecord about data tiles.
Server still calls FormatRecord to keep the validation, then removes the first
line.

For golang/go#69348

Change-Id: I1bea45b3343c58acc90982aaff5d41e32b06ae8c
Reviewed-on: https://go-review.googlesource.com/c/mod/+/618135
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
mjl- authored and matloob committed Nov 1, 2024
1 parent c8a7319 commit dec0365
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sumdb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package sumdb

import (
"bytes"
"context"
"net/http"
"os"
Expand Down Expand Up @@ -150,6 +151,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Data tiles contain formatted records without the first line with record ID.
_, msg, _ = bytes.Cut(msg, []byte{'\n'})
data = append(data, msg...)
}
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
Expand Down
5 changes: 4 additions & 1 deletion sumdb/tlog/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ func ParseTree(text []byte) (tree Tree, err error) {
var errMalformedRecord = errors.New("malformed record data")

// FormatRecord formats a record for serving to a client
// in a lookup response or data tile.
// in a lookup response.
//
// The encoded form is the record ID as a single number,
// then the text of the record, and then a terminating blank line.
// Record text must be valid UTF-8 and must not contain any ASCII control
// characters (those below U+0020) other than newline (U+000A).
// It must end in a terminating newline and not contain any blank lines.
//
// Responses to data tiles consist of concatenated formatted records from each of
// which the first line, with the record ID, is removed.
func FormatRecord(id int64, text []byte) (msg []byte, err error) {
if !isValidRecordText(text) {
return nil, errMalformedRecord
Expand Down

0 comments on commit dec0365

Please sign in to comment.