| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -2793,6 +2793,23 @@ def _create_connection(address, timeout=None, source_address=None): | |
| self.assertIsNotNone(exc) | ||
| self.assertTrue(sock.file_closed) | ||
|
|
||
| def test_tunnel_nonstr_headers(self): | ||
| class CustomObject: | ||
| def __str__(self): | ||
| return 'custom-str' | ||
|
|
||
| self.conn.set_tunnel('destination.com', headers={ | ||
| 'None-Value': None, | ||
| 'Integer-Value': 9, | ||
| 'Custom-Value': CustomObject(), | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYou are converting header values and keys to strings. Maybe the tests can also include this to avoid future regressions?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityGood idea, I think it makes sense. However, I tried adding a non-string key to the test, but it fails earlier: set_tunnel() calls header.lower() on every key to check for a Host header, so non-string keys raise AttributeError there, before _tunnel() is reached. That check predates this issue, so supporting non-string keys would probably be new behavior. I think it'd make sense to update the docs to only mention values. Do you think that's the right approach?
Sorry, something went wrong.
edvilme reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityERROR: test_tunnel_nonstr_headers (test.test_httplib.TunnelTests.test_tunnel_nonstr_headers)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../cpython/Lib/test/test_httplib.py", line 2801, in test_tunnel_nonstr_headers
self.conn.set_tunnel('destination.com', headers={
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'None-Value': None,
^^^^^^^^^^^^^^^^^^^
...<4 lines>...
None: 'none-key',
^^^^^^^^^^^^^^^^^
})
^^
File ".../cpython/Lib/http/client.py", line 974, in set_tunnel
if not any(header.lower() == "host" for header in self._tunnel_headers):
^^^
File ".../cpython/Lib/http/client.py", line 974, in <genexpr>
if not any(header.lower() == "host" for header in self._tunnel_headers):
^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'lower'
----------------------------------------------------------------------
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes, let's just limit the PR to values only if keys didn't work anyway.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThanks for the review, @ZeroIntensity! I reverted str() on keys (since non-string keys already fail earlier in set_tunnel() at the header.lower() check) and updated the docs to mention only values. - header_bytes = str(header).encode("latin-1")
+ header_bytes = header.encode("latin-1")
value_bytes = str(value).encode("latin-1")And thanks a lot, @edvilme, for the discussion here and in the issue. Your review comments helped us find this gap in the set_tunnel() key check, which we wouldn't have noticed otherwise :D
Sorry, something went wrong.
edvilme reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThank YOU, glad you found it :)
Sorry, something went wrong.
All reactions
|
||
| }) | ||
|
|
||
| self.conn.request('HEAD', '/', '') | ||
|
|
||
| self.assertIn(b'None-Value: None\r\n', self.conn.sock.data) | ||
| self.assertIn(b'Integer-Value: 9\r\n', self.conn.sock.data) | ||
| self.assertIn(b'Custom-Value: custom-str\r\n', self.conn.sock.data) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main(verbosity=2) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Restore the previous behaviour of :meth:`http.client.HTTPConnection.set_tunnel` | ||
| where header values that are not strings (such as :const:`None`, :class:`int` | ||
| or other objects) are converted with :class:`str` instead of raising | ||
| :exc:`AttributeError` when the request is sent. |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIf you are using an example domain maybe use that one instead (destination.com is a real non-example domain)?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThanks for the suggestion, @edvilme! I used destination.com to stay consistent with the other tests in TunnelTests. The file also uses example.com, but in this class destination.com is the most common. So I'd lean towards keeping it, but I'm happy to switch to example.com if you think it reads better.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.