Commit Graph
92 Commits
Author SHA1 Message Date
Scott Talbert 91330f9422 Fix WebRequest tests to work with go-httpbin 2.24.0
Unix builds / Ubuntu 18.04 wxGTK 3 compatible 3.0 (push) Canceled after 0s
Unix builds / Ubuntu 24.04 wxGTK ASAN not compatible (push) Canceled after 0s
Unix builds / Ubuntu 18.04 wxGTK UTF-8 (push) Canceled after 0s
Unix builds / Ubuntu 18.04 wxQt (push) Canceled after 0s
Unix builds / Ubuntu 18.04 wxX11 (push) Canceled after 0s
Unix builds / Ubuntu 20.04 wxGTK 3 with clang (push) Canceled after 0s
Unix builds / Ubuntu 22.04 wxGTK with wx containers (push) Canceled after 0s
Unix builds / Ubuntu 18.04 wxDFB (push) Canceled after 0s
Unix builds / Ubuntu 24.04 wxGTK UBSAN (push) Canceled after 0s
Unix builds / Ubuntu 18.04 wxGTK 3 static with gcc 4.8 (push) Canceled after 0s
Unix builds / Ubuntu 18.04 wxGTK 2 (push) Canceled after 0s
CMake builds / Ubuntu 22.04 wxGTK 3 (push) Canceled after 0s
CMake builds / macOS latest wxGTK 3 Unix Makefiles (push) Canceled after 0s
CMake builds / MSW/MSVC wxMSW (push) Canceled after 0s
CMake builds / MSW/Clang wxMSW (push) Canceled after 0s
CMake builds / macOS latest wxOSX Ninja (push) Canceled after 0s
CMake builds / macOS 14 wxOSX Xcode (push) Canceled after 0s
CMake builds / macOS 14 wxIOS (push) Canceled after 0s
CMake builds / MSW/MSVC wxQt 5.15 (push) Canceled after 0s
CMake builds / MSW/MSVC wxQt 6.10 (push) Canceled after 0s
Mac builds / wxMac ARM ASAN not compatible (push) Canceled after 0s
Mac builds / wxMac Universal C++14 (push) Canceled after 0s
Mac builds / wxiOS Simulator on Silicon Mac (push) Canceled after 0s
Mac builds / wxiOS (push) Canceled after 0s
Mac builds / wxMac Intel C++17 (push) Canceled after 0s
Mac Xcode builds / iOS Simulator static (push) Canceled after 0s
Mac Xcode builds / macOS dynamic Release (push) Canceled after 0s
Mac Xcode builds / iOS static Debug (push) Canceled after 0s
MSW builds / wxMSW vs2022 DLL Debug x64 (push) Canceled after 0s
MSW builds / wxMSW vs2022 DLL Release x64 (push) Canceled after 0s
MSW builds / wxMSW vs2022 Debug Win32 (push) Canceled after 0s
MSW builds / wxMSW vs2022 Release arm64 (push) Canceled after 0s
MSW builds / wxMSW vs2026 DLL Release x64 (push) Canceled after 0s
MSW cross-builds / wxMSW 64 bits not compatible (push) Canceled after 0s
MSW cross-builds / wxMSW/Univ (push) Canceled after 0s
MSW cross-builds / wxMSW 32 bits (push) Canceled after 0s
Code Checks / Check Spelling (push) Canceled after 0s
Code Checks / Check Whitespace (push) Canceled after 0s
Code Checks / Check Mixed EOL (push) Canceled after 0s
Code Checks / Check C++ Style (push) Canceled after 0s
Code Checks / Check All Headers In allheaders.h (push) Canceled after 0s
go-httpbin 2.24.0 introduced a change to require relative URLs to begin
with a slash or dot, so update ours to begin with a slash.
2026-07-18 17:52:07 -07:00
Vadim Zeitlin 9a767574ff Add wxWebRequestDebugLogger for details logging of HTTP transfers
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.
2026-01-15 14:51:36 +01:00
Vadim Zeitlin 2be7895e8a Add support for preemptively using "Basic" HTTP authentication
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.
2025-12-22 19:55:34 +01:00
Vadim Zeitlin c3cb1c1d1b Allow reusing POST data when using wxWebRequestCURL
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).
2025-12-22 13:37:23 +01:00
Vadim Zeitlin a5215ae0c3 Document NSURLSession bug with escaped characters in passwords
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.
2025-03-19 00:22:52 +01:00
Vadim Zeitlin 276873960b Fix using reserved characters in URL with wxWebRequestWinHTTP
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.
2025-03-18 23:24:07 +01:00
Vadim Zeitlin dba55ea1e5 Check using reserved characters with SetCredentials()
Verify that using reserved characters in the username and/or password
specified using wxWebAuthChallenge::SetCredentials() works correctly.
2025-03-18 23:22:43 +01:00
Vadim Zeitlin 3d90e174d0 Use wxURI instead of combining URI parts together manually
This is simpler and also fixes a bug in the old code which didn't do it
correctly if the username or password contained any reserved characters.
2025-03-18 23:16:10 +01:00
Vadim Zeitlin de3b760fc6 Revert "Add support for multiple headers with same name to wxWebRequest"
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.
2024-12-20 02:23:24 +01:00
Vadim Zeitlin 0319e8ceb9 Revert "Add headers test"
This reverts commit 0fce060a02 which won't
work any more after upcoming reverting of the commit adding AddHeader().
2024-12-20 00:04:20 +01:00
Vadim Zeitlin 6476b4ed57 Ensure that wxWebSessionImpl remains alive for long enough
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.
2024-12-02 01:22:33 +01:00
Stefan Dinkelacker 38c56c0b36 Fix newly introduced headers test
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.
2024-10-15 23:04:37 +02:00
Stefan Dinkelacker 3b2971e825 Improve test output on failure
The two strings that are compared should now be printed on
test failure.
2024-10-15 21:30:42 +02:00
Stefan Dinkelacker 1000d67c13 Add fallback to URLSession webrequest backend
Multiple HTTP headers with the same name are not supported by the
URLsession API. As a fallback, the last header is used instead.
2024-10-15 18:37:54 +02:00
Stefan Dinkelacker 0fce060a02 Add headers test
The contents of a webrequest header can be checked with the
headers endpoint of the httpbin service.
2024-10-15 16:31:40 +02:00
Stefan Dinkelacker e249e3620d Generalize CheckExpectedJSON() 2024-10-15 16:28:12 +02:00
Stefan Dinkelacker 8395e5733d Add support for multiple headers with same name to wxWebRequest
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.
2024-10-15 09:15:07 +02:00
Stefan Dinkelacker ae6dc7b469 Add GetAllHeaderValues() to wxWebResponse
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.
2024-10-14 21:36:48 +02:00
Vadim Zeitlin 9238b299f5 Switch to using SetBaseURL() in the unit tests
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.
2024-08-21 02:53:33 +02:00
Vadim Zeitlin f3872a6ce9 Add support for specifying proxy in wxWebRequest
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.
2024-08-18 21:15:49 +02:00
Vadim Zeitlin c48e5f0297 Verify that requests are created successfully in the tests
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.
2024-08-18 20:49:26 +02:00
Vadim Zeitlin c4357c79d5 Add WebRequest::Version pseudo-test to see the backend version
This can be notably useful to see libcurl version.
2024-08-17 20:33:51 +02:00
Vadim Zeitlin 18d272e3c7 Fix libcurl backend to handle body with custom requests correctly
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.
2024-08-17 20:33:45 +02:00
Vadim Zeitlin b3af8c5627 Use the same logic for HTTP methods in all backends
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.
2024-08-17 19:05:13 +02:00
Vadim Zeitlin 8fc069dac9 Simplify passing URLs for SSL testing to unit test
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).
2024-08-17 18:30:42 +02:00
Vadim Zeitlin b3b39a31ec Add more flexible way of disabling SSL checks
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.
2024-08-17 18:14:11 +02:00
Vadim Zeitlin 836d5cd42e Show error message in the manual URL tests
This can provide more information about the failure reasons.
2024-08-17 16:51:00 +02:00
Vadim Zeitlin 2edd50fd85 Refactor manual URL tests to avoid code duplication
Add InitManualRequest() to the fixture to avoid having the same code for
the async and sync cases.

No real changes, this is a pure refactoring.
2024-08-17 16:25:13 +02:00
Vadim Zeitlin a56a3cf80d Skip digest auth test with credentials in URL under Ubuntu 18.04
Instead of dealing with this obsolete system, just skip the test there.
2024-08-17 01:58:51 +02:00
Vadim Zeitlin 62531d3df8 Fix tests for response body after authentication
It turns out different httpbin clones produce slightly different
responses, so accept any of them.
2024-08-17 01:58:01 +02:00
Vadim Zeitlin 220f915816 Stop using wxWebAuthChallenge with wxWebRequestSync
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.
2024-08-17 01:32:56 +02:00
Vadim Zeitlin d72937d240 Add tests for specifying credentials in URL for async requests
This didn't work in WinHTTP backend before but now that it does, add
tests checking this.
2024-08-17 01:32:14 +02:00
Vadim Zeitlin 7170cf214e Test response body in authentication tests too
Check that we do receieve the expected body and not just the correct
status.
2024-08-17 01:30:47 +02:00
Vadim Zeitlin bd37069ee3 Add WebRequest::Sync::Manual test
This allows to run wxWebRequestSync::Execute() manually too.

This commit is best viewed with Git --color-moved option.
2024-08-16 21:34:36 +02:00
Vadim Zeitlin 3a2735bd9e Test reading more bytes than one buffer size
Verify that we are not limited to the buffer size when receiving the
remote document.
2024-08-16 20:53:10 +02:00
Vadim Zeitlin a4d9a1b3d8 Add unit tests for wxWebRequestSync
They mirror the existing async tests.
2024-08-16 20:53:10 +02:00
Vadim Zeitlin 1be06280b2 Add comment explaining WX_TEST_WEBREQUEST_URL_SELF_SIGNED
Give an example URL it can be set to for testing.
2024-08-16 18:19:06 +02:00
Maarten Bent abaeec23bf Use go-httpbin instead of python httpbin for the tests
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.
2024-03-13 14:13:51 +01:00
Vadim Zeitlin 378da09c84 Fix typo in "receive" occurring a few times
This is just too annoying to see.
2023-12-27 02:56:20 +01:00
Vadim Zeitlin 8e35b647c3 Use std::unordered_map<> in private wxWebRequest headers
Replace wx synonym with the direct use of the standard class.
2023-04-18 00:42:56 +01:00
Vadim Zeitlin 363f0988cf Replace wxScopedPtr with std::unique_ptr in the tests
Just use the standard class instead of the wx one, as they can be used
in exactly the same way.
2023-03-06 23:34:44 +01:00
PB 88d526660f Replace wxOVERRIDE and wxNOEXCEPT with override and noexcept
Don't use deprecated macros in wxWidgets itself.
2022-10-15 18:10:45 +02:00
Vadim Zeitlin b3b5c8a670 Fix wxWebResponse::GetHeader() and GetURL() in wxMSW
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.
2022-06-20 00:41:13 +02:00
Vadim Zeitlin 9501349b14 Disable wxWebRequest tests using badssl.com
There are DNS problems with resolving it that make the tests fail, see
https://github.com/chromium/badssl.com/issues/500

Require WX_TEST_WEBREQUEST_URL_SELF_SIGNED to be set to the URL to test
instead of hard-coding https://self-signed.badssl.com and don't set this
variable for now to let the tests pass.
2022-04-01 15:27:24 +02:00
Vadim Zeitlin de2b81b06f Ignore error in another wxWebRequest test under AppVeyor
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.
2021-08-05 23:42:53 +01:00
Vadim Zeitlin b03eaceea6 Disable WebRequest::SSL::Ignore unit test under AppVeyor
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.
2021-08-04 18:24:28 +02:00
Vadim Zeitlin 55d57c0f68 Remove another obsolete Borland hdrstop pragma
See f57f214122 (Remove BCC-specific hdrstop pragma from everywhere,
2020-10-12).
2021-08-01 00:43:31 +01:00
Vadim Zeitlin 360268ee25 Extend life time of wxWebRequest while it is in process
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.
2021-03-24 17:45:01 +01:00
Vadim Zeitlin 0548a06905 Check the values from wxWebRequestEvent in the unit test too
In addition to checking that wxWebRequest itself is filled with the
expected values, verify that the same values are returned via
wxWebRequestEvent.
2021-03-24 16:33:05 +01:00
Vadim Zeitlin 8d01aaf783 Make WebRequest::Get::Param unit test more forgiving
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.
2021-03-06 14:44:56 +01:00