Skip to content

Commit

Permalink
results: Fix Headers encoding (#507)
Browse files Browse the repository at this point in the history
* Revert "results: Faster JSON encoding and decoding (#506)"

This reverts commit 3629602.

* results: Fix headers encoding
  • Loading branch information
tsenart authored Mar 25, 2020
1 parent 3629602 commit d9b795a
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 302 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ vendor
*.lz

.DS_Store
.idea
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ require (
github.com/miekg/dns v1.1.17
github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25
github.com/tsenart/go-tsz v0.0.0-20180814232043-cdeb9e1e981e
github.com/valyala/fastjson v1.5.0
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
pgregory.net/rapid v0.3.3
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25 h1:7z3LSn867ex6
github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25/go.mod h1:lbP8tGiBjZ5YWIc2fzuRpTaz0b/53vT6PEs3QuAWzuU=
github.com/tsenart/go-tsz v0.0.0-20180814232043-cdeb9e1e981e h1:bB5SXzQmSUsJCmjPDN9fKYx3SSDER5diSjlN6TefTCc=
github.com/tsenart/go-tsz v0.0.0-20180814232043-cdeb9e1e981e/go.mod h1:SWZznP1z5Ki7hDT2ioqiFKEse8K9tU2OUvaRI0NeGQo=
github.com/valyala/fastjson v1.5.0 h1:DGrb4wEYso2HdGLyLmNoyNCQnCWfjd8yhghPv5/5YQg=
github.com/valyala/fastjson v1.5.0/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -59,3 +57,5 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
48 changes: 42 additions & 6 deletions lib/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"strconv"
"strings"
"time"

"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)

func init() {
Expand Down Expand Up @@ -252,15 +255,48 @@ func NewCSVDecoder(r io.Reader) Decoder {
r.Method = rec[9]
r.URL = rec[10]

pr := textproto.NewReader(bufio.NewReader(
base64.NewDecoder(base64.StdEncoding, strings.NewReader(rec[11]))))
hdr, err := pr.ReadMIMEHeader()
if err != nil {
return err
if rec[11] != "" {
pr := textproto.NewReader(bufio.NewReader(
base64.NewDecoder(base64.StdEncoding, strings.NewReader(rec[11]))))
hdr, err := pr.ReadMIMEHeader()
if err != nil {
return err
}
r.Headers = http.Header(hdr)
}
r.Headers = http.Header(hdr)

return err
}
}

//go:generate easyjson -no_std_marshalers -output_filename results_easyjson.go results.go
//easyjson:json
type jsonResult Result

// NewJSONEncoder returns an Encoder that dumps the given *Results as a JSON
// object.
func NewJSONEncoder(w io.Writer) Encoder {
var jw jwriter.Writer
return func(r *Result) error {
(*jsonResult)(r).MarshalEasyJSON(&jw)
if jw.Error != nil {
return jw.Error
}
jw.RawByte('\n')
_, err := jw.DumpTo(w)
return err
}
}

// NewJSONDecoder returns a Decoder that decodes JSON encoded Results.
func NewJSONDecoder(r io.Reader) Decoder {
rd := bufio.NewReader(r)
return func(r *Result) (err error) {
var jl jlexer.Lexer
if jl.Data, err = rd.ReadBytes('\n'); err != nil {
return err
}
(*jsonResult)(r).UnmarshalEasyJSON(&jl)
return jl.Error()
}
}
223 changes: 223 additions & 0 deletions lib/results_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9b795a

Please sign in to comment.