add workaround for Twisted when receiving absolute-form URI in HTTP request #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
As reported by localstack/localstack#11652, we've had an issue in LocalStack because the request would contain the whole URI in the
request.path.This can be traced down to Twisted with a simple reproducer:
Sending a request with an absolute-form URI (see RFC7230: https://tools.ietf.org/html/rfc7230#section-5.3.2) like
GET http://localhost:4566/path HTTP/1.1will printrequest.path=http://localhost:4566/path.When using the WSGI compatible part of twisted, it will even replace the first char by
/, leading toPATH_INFOin the environ to be/ttp://localhost:4566/path.This is only a workaround until we can fix it in Twisted directly, and if they're open to it.
Seems an issue was opened in 2010 about it: twisted/twisted#4371
Changes
/, which is something we've been doing directly on theRAW_URIin LocalStack for a while now (with fix get_raw_path parsing localstack#8962).localstack-twistedbecause it seems Twisted changed the logic around the casing of headers to use a_NameEncoder, which breaks our logic to preserve header casing. See https://github.com/localstack/rolo/actions/runs/11298814586/job/31428556695?pr=23 and #9743 #12191 Faster, more correct HTTP headers twisted/twisted#12264