-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture HTTP headers in results #474
Conversation
Headers are written in wire format. CSV output uses base64 to encode headers. Fixes tsenart#303
lib/attack.go
Outdated
@@ -392,5 +393,9 @@ func (a *Attacker) hit(tr Targeter, name string) *Result { | |||
res.Error = r.Status | |||
} | |||
|
|||
var hdr bytes.Buffer | |||
r.Header.Write(&hdr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of r.Header.Write
is not checked (from errcheck
)
@@ -217,6 +254,15 @@ func NewCSVDecoder(r io.Reader) Decoder { | |||
|
|||
r.Method = rec[9] | |||
r.URL = rec[10] | |||
if len(rec) > 11 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we set FieldsPerRecord = 12
, then this is always going to be true, or else an error would be returned by read.
FieldsPerRecord is the number of expected fields per record. If FieldsPerRecord is positive, Read requires each record to have the given number of fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing this in a follow up commit. Thanks for the contribution!
This commit improves the performance of JSON encoding and decoding of `Results`. Additionally, it fixes a regression introduced in #474 that didn't produce valid JSON for HTTP headers. A test is added that validates the JSON encoding matches the one produced by the `encoding/json`. ``` name old time/op new time/op delta ResultEncodings/json-encode-16 690ns ±12% 297ns ± 0% -56.94% (p=0.000 n=9+9) ResultEncodings/json-decode-16 1.05µs ± 1% 0.03µs ± 1% -97.47% (p=0.000 n=10+8) name old alloc/op new alloc/op delta ResultEncodings/json-encode-16 804B ±87% 0B -100.00% (p=0.000 n=9+10) ResultEncodings/json-decode-16 310B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ResultEncodings/json-encode-16 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) ResultEncodings/json-decode-16 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) ```
* Add .idea to .gitignore * results: Faster JSON encoding and decoding This commit improves the performance of JSON encoding and decoding of `Results`. Additionally, it fixes a regression introduced in #474 that didn't produce valid JSON for HTTP headers. A test is added that validates the JSON encoding matches the one produced by the `encoding/json`. ``` name old time/op new time/op delta ResultEncodings/json-encode-16 690ns ±12% 297ns ± 0% -56.94% (p=0.000 n=9+9) ResultEncodings/json-decode-16 1.05µs ± 1% 0.03µs ± 1% -97.47% (p=0.000 n=10+8) name old alloc/op new alloc/op delta ResultEncodings/json-encode-16 804B ±87% 0B -100.00% (p=0.000 n=9+10) ResultEncodings/json-decode-16 310B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ResultEncodings/json-encode-16 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) ResultEncodings/json-decode-16 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) ```
Update README to follow tsenart#474
Headers are written in wire format. CSV output uses base64 to encode
headers.
Fixes #303