Skip to content

Commit dec0365

Browse files
mjl-matloob
authored andcommitted
sumdb: make data tiles by Server compatible with sum.golang.org
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]>
1 parent c8a7319 commit dec0365

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sumdb/server.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package sumdb
77

88
import (
9+
"bytes"
910
"context"
1011
"net/http"
1112
"os"
@@ -150,6 +151,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
150151
http.Error(w, err.Error(), http.StatusInternalServerError)
151152
return
152153
}
154+
// Data tiles contain formatted records without the first line with record ID.
155+
_, msg, _ = bytes.Cut(msg, []byte{'\n'})
153156
data = append(data, msg...)
154157
}
155158
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")

sumdb/tlog/note.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ func ParseTree(text []byte) (tree Tree, err error) {
7373
var errMalformedRecord = errors.New("malformed record data")
7474

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

0 commit comments

Comments
 (0)