Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
webtest.openURL sends an absolute URI when passed as "url" #1621
The RFC's state that absolute URI's are not allowed to be sent to a server unless it is a proxy server.
This is my work-around in a pytest fixture, this works for me. Most likely
from cherrypy.test.webtest import openURL from urlparse import urlsplit _broken_openURL = openURL def openURL(url, *args, **kw): scheme, authority, path, qs, fragment = urlsplit(url) return _broken_openURL(path + '?' + qs, *args, **kw) webtest.openURL = openURL
@bertjwregeer so now
As you can see,
On the other hand I can understand why you'd want to have a function supporting absolute-uri notation. Would you be satisfied with a separate function wrapping original one?
No, this doesn't satisfy my needs. All of our testing uses
The above is an
See https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html section 5.1.2:
Since in almost all cases of testing, when the user passes a URL to
I was a little confused by this openURL thing until I realized that the
In the systems where we use webtest, we pass only the uri portion of the request and not an absolute URL.
I think the user shouldn't pass a full URL as the URL parameter to openURL. openURL is not trying to mimic requests, but is instead soliciting the request uri as will be passed in the HTTP request line.
If I were you, I'd rewrite your tests not to have absolute URLs at all... or if having them is meaningful and useful, I'd continue to use your adapter wrapper. I'd not be opposed to supplying that adapter wrapper as a convenience if you can present a good reason why cheroot should support that interface.
@jaraco all of our API's currently return full URL's in JSON responses (using a standard known as Shoji) which would just be used directly in
Now that the changes have been made in cheroot to no longer accept the
I suggested the fix above because the goal was to send a request to the webtest server, and it is now expecting a valid request URI. I feel that stripping off the scheme/domain name makes sense to maintain backwards compatibility with existing test code, rather than forcing all users to rewrite their tests because cheroot has become more strict in what you may send it.
I think now I understand why openAbsoluteURI isn't any help. The typical use of webtest is to invoke WebCase.getPage, which hard-codes the call to openURL. Thus, the addition of openAbsoluteURI provides little value for that use case. Moreover, it seems we've made a backward-incompatible change without providing guidance or clarity on how to adapt.
In cherrypy/cheroot (commit referenced above), I've taken a different tack to address this need. @bertjwregeer , can you take a look and see if the new approach will address your needs?