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
Enable prepared statements over http.client._MAXLINE limit #173
Conversation
@@ -9,6 +9,7 @@ | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
import http |
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.
from http.client import _MAXLINE
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.
That actually doesn't comply with the pre-commit check as it doesn't support private attributes.
tests/integration/test_dbapi_integration.py:15: error: Module "http.client" has no attribute "_MAXLINE"
Found 1 error in 1 file (checked 32 source files)
I think we don't want to import http.client at all in the module namespace as we only rely on some private property. I moved the import to the test itself.
trino/client.py
Outdated
headers.append(line) | ||
if line in (b'\r\n', b'\n', b''): | ||
break | ||
hstring = b''.join(headers).decode('iso-8859-1') |
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: header_string
trino/client.py
Outdated
|
||
|
||
# Disable header limit to avoid LineTooLong('got more than 65536 bytes when reading header line') | ||
disable_header_limit() |
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.
Could this be moved into e.g ClientSession
or TrinoRequest
class?
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.
It feels a lot less pythonic to me. it works of course and hides this override in TrinoRequest
instead of the module's namespace.
class TrinoRequest:
@staticmethod
def _disable_header_limit():
import http.client
import email.parser
from http.client import HTTPMessage, _MAXLINE
def parse_headers(fp, _class=HTTPMessage):
headers = []
while True:
line = fp.readline(_MAXLINE + 1)
headers.append(line)
if line in (b'\r\n', b'\n', b''):
break
header_string = b''.join(headers).decode('iso-8859-1')
return email.parser.Parser(_class=_class).parsestr(header_string)
http.client.parse_headers = parse_headers
# Disable header limit to avoid LineTooLong('got more than 65536 bytes when reading header line')
_disable_header_limit.__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.
I created a helper class for this override. Let me know WDYT.
d08c906
to
e3ecce6
Compare
e3ecce6
to
00dd234
Compare
Fixes #148
Headers can become much longer then what is currently suported in Python's
http.client
. This code patches the header parsing fromhttp.client
to be able to parse the headers coming back from the Trino server.Test is included. when removing the
disable_header_limit()
in client.py, the test will fail withrequests.exceptions.ConnectionError: ('Connection aborted.', LineTooLong('got more than 65536 bytes when reading header line'))
.