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

Don't reuse the existing request for digest based auth. #12

Merged
merged 8 commits into from
Sep 17, 2016

Conversation

opalmer
Copy link
Contributor

@opalmer opalmer commented Sep 8, 2016

For digest based auth. we were reusing the request anytime we received StatusUnauthorized from the server. The first attempt to fix this was to reconstruct the request which worked but was more complicated. This PR improves on the previous approach by:

  • Removing the special digest only code in Do()
  • Sending a request to the target URI without a body. This reduces the amount of traffic to the server and also helps to allow the http client to reuse the connection in some cases.

The above was mostly sourced from commit 30db148.

In some cases, such as when handling digest auth,
we might need to retry the request.  We shouldn't
be using the original request object however
because the Body will have been read by the first
request.  To fix this a new argument has been added
to Do() so that the original body can be passed along
to the next request.

Note, the original body could be copied.  But this seemed
like a better implementation because it saves a couple
of allocations and potentially memory too depending on
the body size.
@opalmer opalmer added the bug label Sep 8, 2016
@coveralls
Copy link

coveralls commented Sep 8, 2016

Coverage Status

Coverage decreased (-0.04%) to 10.658% when pulling a2569a1 on digest_bug_fix into 757826d on master.

@opalmer
Copy link
Contributor Author

opalmer commented Sep 8, 2016

@andygrunwald, FYI this is still a work in progress but I'm hoping to finish it in the next couple of days. For the record, the existing APIs seem to work in most cases. However this code fails complaining about differences in the body versus the content length:

package main

import (
    "github.com/andygrunwald/go-gerrit"
    log "github.com/Sirupsen/logrus"
)

func main()  {
    client, err := gerrit.NewClient("http://localhost:8081/", nil)
    if err != nil {
        panic(err)
    }

    user := ""
    password := ""
    client.Authentication.SetDigestAuth(user, password)

    input := &gerrit.ReviewInput{
        Message: "FOOBAR",
        Drafts: "PUBLISH_ALL_REVISIONS",
    }
    info, response, err := client.Changes.SetReview(
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        input,
    )
    log.Info(info)
    log.Info(response)
    log.Info(err)
    if err != nil {
        panic(err)
    }
}

Right now the changes are causing 401 Unauthorized responses. Once that's fixed this will probably be ready for a review.

Without this bit of code retrying the
request with the previous uri results
in a/ being double prepended.
@coveralls
Copy link

coveralls commented Sep 9, 2016

Coverage Status

Coverage decreased (-0.03%) to 10.668% when pulling 3eb071c on digest_bug_fix into 757826d on master.

@coveralls
Copy link

coveralls commented Sep 9, 2016

Coverage Status

Coverage decreased (-0.02%) to 10.678% when pulling d25ee1f on digest_bug_fix into 757826d on master.

@andygrunwald
Copy link
Owner

Right now i am on vacation. Will Be back in 10 days. Ok?

Am Freitag, 9. September 2016 schrieb Coveralls :

[image: Coverage Status] https://coveralls.io/builds/7810053

Coverage decreased (-0.02%) to 10.678% when pulling d25ee1f
d25ee1f
on digest_bug_fix
into 757826d
757826d
on master
.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#12 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AATiQEIGNYDnwI4ZddHiA_boBASoKJN0ks5qoLsMgaJpZM4J3jMf
.

@opalmer
Copy link
Contributor Author

opalmer commented Sep 9, 2016

Not a problem, still working out a few issues anyway. Enjoy your vacation!

@andygrunwald
Copy link
Owner

Thank you. Will do. Croatia is amazing so far. Don't work to much / hard :)

Am Freitag, 9. September 2016 schrieb opalmer :

Not a problem, still working out a few issues anyway. Enjoy your vacation!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#12 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AATiQEpyMM7ieDEwDFvcwS5nS98rQ6cuks5qoWwHgaJpZM4J3jMf
.

For digest based auth. we were reusing the request
anytime we received StatusUnauthorized from the
server. The first attempt to fix this was to
reconstruct the request which worked but was
more complicated.  This commit improves on the
previous approach by:

  * Removing the special digest only code in Do()
  * Removing the need to modify all of go-gerrit to
    pass in the request input to Do()
  * Sending a request to the target URI without a
    body. This reduces the amount of traffic to the server
    and also help to allow the http client to reuse the
    connection in some cases.
@coveralls
Copy link

coveralls commented Sep 13, 2016

Coverage Status

Coverage decreased (-0.02%) to 10.675% when pulling 30db148 on digest_bug_fix into 757826d on master.

@opalmer opalmer changed the title Don't reuse the *http.Request in Do() Don't reuse the existing request for digest based auth. Sep 13, 2016
@coveralls
Copy link

coveralls commented Sep 13, 2016

Coverage Status

Coverage decreased (-0.04%) to 10.66% when pulling 1ac49aa on digest_bug_fix into 757826d on master.

@opalmer
Copy link
Contributor Author

opalmer commented Sep 13, 2016

@andygrunwald, this ready for a look when you get back I think. I've also opened up #13 which lead to the discovery of this bug. Unfortunately, this PR only partially fixes #13 which I'm still working on but that should probably be addressed in another PR.

@coveralls
Copy link

coveralls commented Sep 17, 2016

Coverage Status

Coverage decreased (-0.04%) to 10.66% when pulling f655819 on digest_bug_fix into 757826d on master.

@andygrunwald andygrunwald merged commit f655819 into master Sep 17, 2016
@andygrunwald
Copy link
Owner

Merged manually. Thank you @opalmer

@andygrunwald andygrunwald deleted the digest_bug_fix branch September 17, 2016 08:27
@opalmer opalmer modified the milestone: 0.1.0 Oct 8, 2016
@opalmer opalmer self-assigned this Oct 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants