-
Notifications
You must be signed in to change notification settings - Fork 247
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
Allow users to add custom http headers when using hs2-http (#557) #558
base: master
Are you sure you want to change the base?
Allow users to add custom http headers when using hs2-http (#557) #558
Conversation
impala/tests/test_http_connect.py
Outdated
# Save the http headers from the message in a class variable. | ||
RequestHandlerProxy.saved_headers = self.decode_raw_headers() | ||
# Forward the http post message to Impala and get a response message. | ||
response = requests.post(url="http://localhost:28000/cliservice", |
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.
The port should be configurable with env var IMPYLA_TEST_HTTP_PORT
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.
Done, thanks
impala/tests/test_http_connect.py
Outdated
|
||
def decode_raw_headers(self): | ||
"""Decode a list of header strings into a list of tuples, each tuple containing a | ||
key-value pair. The details of how to get the headers are differs between Python2 |
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.
nit: headers are differs -> are different/differs?
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.
Fixed, thanks
impala/_thrift_api.py
Outdated
# Update HTTP headers based on the saved cookies and auth mechanism. | ||
# Set the user-defined callback function which adds custom HTTP headers to outgoing | ||
# messages. | ||
def setGetUserDefinedCustomHeadersFunc(self, func): |
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.
Is this used anywhere?
Also, couldn't the test use this function to set the callback so that passing get_user_custom_headers_func through constructors can be avoided?
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.
Not used and removed.
I agree that it is ugly to have to change the constructors. But the ImpalaHttpClient is hidden away so it is hard to call methods on it, especially before connect() is called. And connect() sends messages which we might want to know about.
I welcome suggestions for better structure.
) In a modern Impala deployment hs2-http protocol is used in a system where http messages pass through one or more http proxies. Some of these proxies add their own http message headers to messages as they are forwarded. It would be useful to test Impala with some of the message headers that are added by http proxies. In particular the case where there are multiple http headers with the same name is hard to simulate with clients such as Impyla or Impala Shell. This is partly because these clients store http headers in a Python dict which does not allow duplicate keys. Extend the Impyla connect() method to add a 'get_user_custom_headers_func' parameter. This specifies a function that is called as http message headers are being written. The function should return a list of tuples, each tuple containing a key-value pair. This allows duplicate headers to be set on outgoing messages. TESTING Add test code which implements a reverse http proxy, which allows test code to access the outgoing http message headers generated by Impyla. Add a test using this proxy which validates the new feature. The new test code requires a new python package 'requests'. I think there is not away to add this requirement automatically so I added a note to README.md All tests pass on Python2 and Python3. Fix TestHS2FaultInjection to use setup_method() and teardown_method() so as to work in Python3
1141dde
to
14b7ec6
Compare
In a modern Impala deployment hs2-http protocol is used in a system where http messages pass through one or more http proxies. Some of these proxies add their own http message headers to messages as they are forwarded. It would be useful to test Impala with some of the message headers that are added by http proxies. In particular the case where there are multiple http headers with the same name is hard to simulate with clients such as Impyla or Impala Shell. This is partly because these clients store http headers in a Python dict which does not allow duplicate keys.
Extend the Impyla connect() method to add
a 'get_user_custom_headers_func' parameter. This specifies a function that is called as http message headers are being written. The function should return a list of tuples, each tuple containing a key-value pair. This allows duplicate headers to be set on outgoing messages.
TESTING
Add test code which implements a reverse http proxy, which allows test code to access the outgoing http message headers generated by Impyla. Add a test using this proxy which validates the new feature.
The new test code requires a new python package 'requests'. I think there is not away to add this requirement automatically so I added a note to README.md
All tests pass on Python2 and Python3.
Fix TestHS2FaultInjection to use setup_method() and teardown_method() so as to work in Python3