Skip to content
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

mark responses as success in no redirect following mode. #222

Merged

Conversation

keijiyoshida
Copy link
Contributor

Issue which this PR solves

Vegeta does not mark responses as success when -1 is set to the attack -redirects option. Bytes In, Bytes Out, Success and Status Codes of a report are zeros as below:

echo "GET http://xxxx.xxxx" | vegeta attack -redirects -1 -rate 1 -duration 10s | tee results.bin | vegeta report
Requests      [total, rate]            10, 1.11
Duration      [total, attack, wait]    9.003078071s, 8.999999898s, 3.078173ms
Latencies     [mean, 50, 95, 99, max]  12.427662ms, 3.246776ms, 3.823605ms, 3.823605ms, 96.816248ms
Bytes In      [total, mean]            0, 0.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  0.00%
Status Codes  [code:count]             0:10
Error Set:

Changes in this PR

Have a.client.CheckRedirect return http.ErrUseLastResponse when -1 is set to the attack -redirects option. By doing this, Go's HTTP client does not follow redirects and returns the first HTTP response with its body unclosed. See https://golang.org/src/net/http/client.go?h=ErrUseLastResponse#L398 for the details.

@keijiyoshida keijiyoshida force-pushed the feature/no-redirect-follow-http-status branch 2 times, most recently from c88138a to b5ac0f2 Compare March 3, 2017 04:13
lib/attack.go Outdated
a.client.CheckRedirect = func(_ *http.Request, via []*http.Request) error {
if len(via) > n {
return fmt.Errorf("stopped after %d redirects", n)
if n == NoFollow {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have this code be the simpler version:

a.client.CheckRedirect = func(_ *http.Request, via []*http.Request) error {
    switch {
    case n == NoFollow:
        return http.ErrUseLastResponse
    case n < len(via):
        return fmt.Errorf("stopped after %d redirects", n)
    default:
        return nil
    }
}

@tsenart
Copy link
Owner

tsenart commented Mar 4, 2017

Can you please add a regression test that fails for the bug you're fixing?

@keijiyoshida keijiyoshida force-pushed the feature/no-redirect-follow-http-status branch from b5ac0f2 to 1629530 Compare March 14, 2017 02:29
@keijiyoshida
Copy link
Contributor Author

@tsenart Thanks for your reviewing and sorry for the late response. I fixed the module and added a regression test. Thanks.

@tsenart tsenart merged commit d5ef2b8 into tsenart:master Mar 18, 2017
@keijiyoshida keijiyoshida deleted the feature/no-redirect-follow-http-status branch March 19, 2017 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants