Skip to content

Conversation

birdsarah
Copy link
Contributor

Fixes #3660

Sarah Bird added 2 commits March 15, 2017 17:39
Have also confirmed that this test would fail on original implementation
of add_header that was fixed in 55ed929
Test method seperately, and then test that RemoteConnection calls it.
@birdsarah
Copy link
Contributor Author

@davehunt, agree this was cumbersome to test.

If my code split out is really undesirable, should it be straight forward to just do the very small fix to the code and rework the tests now I figured out all the mocking.

But, it seems to me that _request needs breaking up into smaller methods to allow for easier unit testing, so I figured I might as well start down that path.

Putting the header addition on the Request class seemed reasonable, but also see the first commit where I just made it a method on RemoteConnection - in case that's preferable.

Copy link
Contributor

@davehunt davehunt left a comment

Choose a reason for hiding this comment

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

This looks great @birdsarah! Let me know if you have time to address my comments. If not, I'm happy to merge this as it is.

if parsed_url.username:
base64string = base64.b64encode('{0.username}:{0.password}'.format(parsed_url).encode())
request.add_header('Authorization', 'Basic {}'.format(base64string).decode())
request.add_remote_connection_headers(parsed_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of splitting this out. We could take it a step further though and remove the duplication from lines 450-458. Perhaps a get_remote_connection_headers that takes the URL and a boolean for keep_alive? It's also fine if you want to push this to a later date.

parsed_url.query,
parsed_url.fragment)
)
request = Request(cleaned_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for the cleaned_url. Can we not just use the original url here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@birdsarah
Copy link
Contributor Author

birdsarah commented Mar 17, 2017

Sorry for delay - will look at your suggestions in the morning...

@birdsarah
Copy link
Contributor Author

Ready! I factored out the other headers declaration so there's no duplication. Please note the following:

  • The non keep-alive headers will now also have the user agent "User Agent": "Python http auth"
  • The keep-alive headers no longer have the header method: parsed_url.path which I don't believe is a valid, or used, header value.

@davehunt davehunt merged commit 7d1286e into SeleniumHQ:master Mar 18, 2017
@davehunt
Copy link
Contributor

Thanks @birdsarah!

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