Allow getting detailed information about the operations performed by
wxWebRequest, at least when using libcurl-based backend, which provides
good built-in support for this, and partially when using WinHTTP.
Note that the debug logger is set at the session level and not for each
request: this is less flexible, but more convenient and is probably how
it will always be used in practice.
See #26086.
Add UseBasicAuth() which allows to avoid an extra round trip to the
server due to trying to access a protected URL without providing the
credentials first and only sending them in response to 401 response.
For libcurl, simply set authentication method to CURLAUTH_BASIC and let
the library handle everything. For the other backends, add the required
"Authorization" header ourselves, as they don't seem to have any support
for doing preemptive authentication on their own.
Set seek callback to allow libcurl to reuse the data being uploaded when
it has to redo the HTTP request, e.g. because of redirection after a 301
or resubmitting it with correct authentication data after a 401.
Add a test checking that this works correctly, although it has to be
disabled for WinHTTP for now as it doesn't handle 307/308 redirects
automatically (see #26046).
They are simply not handled properly by NSURLRequest, apparently, and
there doesn't seem to be any simple way around it, so for now just
document that this doesn't work and adjust the test to avoid using
reserved characters in the password when using NSURLSession-based
backend.
Although username/password with the reserved characters worked correctly
when using them via wxWebAuthChallenge::SetCredentials() (see the parent
commit), specifying such usernames/passwords in the URL itself didn't
work correctly because they were used in their percent-encoded form, as
this is how WinHttpCrackUrl() returns them to us.
Fix this by decoding them ourselves.
Add a test which works now but would fail when using WinHTTP backend
before.
This reverts commit 8395e5733d because
HTTP standard says that senders MUST NOT generate multiple lines with
the same header, with the only exception of Set-Cookie, so we shouldn't
provide a way to do it.
That commit also introduced a nasty regression with the programs calling
AddCommonHeader("User-Agent") not working at all any more after it
because WinHTTP refuses to send a request with multiple copies of this
header.
Also partially reverts 1000d67c13 which
was done later but is logically part of the same commit that is being
reverted.
See #24881.
This object shouldn't be destroyed as long as there are any
wxWebRequests using it still alive, as destroying them after the session
would result in a crash, so replace a (possibly dangling) reference to
wxWebSessionImpl in wxWebRequestImpl with a shared pointer, which keeps
it alive for as long as necessary.
See #24969.
The format of the generated JSON by the httpbin service for
multiple headers with the same name differs between platforms.
These headers are sometimes put into a JSON array and sometimes
concatenated into a single comma-separated string.
wxWebRequest::AddHeader() was added to accompany the existing
SetHeader() method. In wxWebSession, AddCommonHeader() did exist
already but behaved like setting a header. Its behavior was adapted
to its name and SetCommonHeader() was added with the old behavior
to accompany AddCommonHeader().
The WinHTTP and CURL implementations of wxWebRequest do now append
multiple headers of the same name. The URLSession implementation
follows in the next commits.
HTTP headers like Set-Cookie can be present multiple times in a
web response by definition. The existing GetHeader() method is
not sufficient to cope with this situation.
This commit already adds an implementation for Windows.
Linux and macOS follow in the next commits.
Instead of constructing the full URLs manually simplify the test by
using SetBaseURL().
This required removing leading slashes from all relative URLs used in
the test, but there are no other real changes.
Allow disabling the proxy used by default or specifying a custom proxy.
Unfortunately NSURLSession implementation doesn't support neither paths
in the proxy URLs nor proxy authentication when using synchronous
requests, but there doesn't seem to be any way around it.
This may not happen if the session couldn't be initialized for some
reason and it's better to stop the test immediately in this case than to
give a lot of other confusing errors later.
Previously body wasn't sent, even if it was specified, for the custom
requests such as DELETE.
Fix this by setting CURLOPT_UPLOAD and CURLOPT_INFILESIZE options if the
body is present for any method except POST, which is handled specially
by libcurl, and not only for PUT.
Add a unit test checking that this works now.
No real changes, just add GetHTTPMethod() helper function in the base
wxWebRequestImpl class and use it in all backends: previously, WinHTTP
and NSURLSession ones already did the same thing, but each in their own
way, while libcurl backend used a different logic which was mostly
equivalent, but this was not really obvious, while now it should be.
Also add a test for using a custom method (DELETE), for now without
body, as this is (still) not supported by libcurl backend.
Allow defining a single WX_TEST_WEBREQUEST_USE_BADSSL environment
variable to use badssl.com for all tests instead of bothering with
defining each variable separately (but it's still possible to do it and
override the default values implied by WX_TEST_WEBREQUEST_USE_BADSSL).
Allow disabling host name checks too, to make the connection completely
insecure by accepting any certificate for any host.
Incidentally, this also allows checking for valid certificate for any
host, even if this doesn't seem tremendously useful.
Document that disabling any kind of verification in NSURLSession-based
backend disables all of them and also significantly refactor and extend
unit tests checking for this.
The wxWebAuthChallenge-based approach seems to be unnecessarily
complicated for the synchronous use case and isn't supported by the
current NSURLSession backend implementation (although this could be
changed by rewriting it to use a different delegate for the sync
requests and remembering wxWebAuthChallenge in it between the calls to
Execute()).
For now, just drop support for it and require specifying the
authentication information in the URL itself.
Python version is too fragile and gets constantly broken by the changes
in Python ecosystem, so switch to the hopefully more stable Go version.
Closes#23398.
These functions returned strings of wrong size, with some junk after the
end of the actual string, due to a confusion between the size of the
buffer in bytes used by the WinHTTP functions and the length of the
buffer in (wide) characters used by wxWCharBuffer.
Fix this and add a unit test checking that the expected header is
returned.
See #22549.
Closes#22181.
This is similar to b03eaceea6 (Disable WebRequest::SSL::Ignore unit test
under AppVeyor, 2021-08-04) and just warns about the wxWebRequest
cancelling test failure when running it under AppVeyor instead of
failing the entire test suite, as this does happen sporadically (but
regularly) there for as yet unknown reason.
This test sporadically fails in builds with different compilers (both
MSVC and gcc) there for unknown reasons. Until we can find, and fix, the
underlying problem, disable this test to avoid spurious CI failures.
We already did it just before processing the state change event, but
this was too late, as the object could have been already deleted by then
and this actually happened with the example from wxWebRequest
documentation.
Do it earlier now, as soon as the request becomes active, which normally
happens when Start() is called, and keep the reference until the event
is processed after the request reaches one of the final states
(completed, failed or cancelled).
Add a unit test checking that deleting the wxWebRequest object doesn't
prevent the request from running to the completion any more.
The simple test added in 59a8f26b01 (Add a unit test for wxWebRequest
query using URL parameters, 2021-03-06) worked when using httpbin.org,
but not when running httpbin locally, as it doesn't pretty-print JSON by
default.
Skip optional whitespace to make it work in both cases.