search: add LimitReader around JSON decoding. add some TODOs

Change-Id: I98069ef0aeb8c96cdc997c138222e0344981ead8
This commit is contained in:
Brad Fitzpatrick 2013-11-08 14:49:23 -05:00
parent 4d620d2c60
commit 4c70e14310
1 changed files with 10 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
@ -33,13 +34,7 @@ import (
type SortType int
// TODO: extend/merge/delete this type? probably dups in this package.
type BlobMeta struct {
Ref blob.Ref
Size int
MIMEType string
}
// TODO: add MarshalJSON and UnmarshalJSON to SortType
const (
UnspecifiedSort SortType = iota
LastModifiedDesc
@ -48,6 +43,13 @@ const (
CreatedAsc
)
// TODO: extend/merge/delete this type? probably dups in this package.
type BlobMeta struct {
Ref blob.Ref
Size int
MIMEType string
}
type SearchQuery struct {
Constraint *Constraint `json:"constraint"`
Limit int `json:"limit"` // optional. default is automatic.
@ -55,7 +57,7 @@ type SearchQuery struct {
}
func (q *SearchQuery) fromHTTP(req *http.Request) error {
dec := json.NewDecoder(req.Body)
dec := json.NewDecoder(io.LimitReader(req.Body, 1<<20))
if err := dec.Decode(q); err != nil {
return err
}