Commit Graph

69716 Commits

Author SHA1 Message Date
Vadim Zeitlin
970ab0a1ae Make sure wxEVT_WEBREQUEST_DATA is processed in the main thread
This event was processed in a worker thread, which was different from
all the other events and also almost surely not thread-safe, so change
this and queue it for processing in the main thread instead.

Use wxMemoryBuffer instead of non-owning pointer in wxWebRequestEvent
and reset the buffer used internally every time to ensure the data is
still available by the time the event is processed.

Also increase the amount of data downloaded in the "advanced" page of
the sample as it has to be greater than wxWEBREQUEST_BUFFER_SIZE, which
is currently 64KiB, to have a chance of seeing the value actually
change, otherwise all the data arrives in a single event. As it is,
using the maximal size supported by the httpbin service, we only get 2
events.
2021-01-16 23:53:15 +01:00
Vadim Zeitlin
4c19572d9d Use switch over enum-valued variable rather than "if"s
No real changes, just make sure we use an (exhaustive) switch rather
than a less obvious sequence of if statements.
2021-01-16 23:33:18 +01:00
Vadim Zeitlin
c41041a3b6 Show error description if available when Cancel() test fails
Hopefully this might provide more information about the failure of this
test in MSVS 2008 build on AppVeyor.
2021-01-16 21:21:08 +01:00
Vadim Zeitlin
0777fda680 Rearrange states in the switch in a more logical order
No real changes, just try to organize the code in a more logical order.
2021-01-16 15:07:18 +01:00
Vadim Zeitlin
0742ae9091 Verify that native handle is available when state becomes active
Check that GetNativeHandle() behaves as documented.
2021-01-16 15:05:38 +01:00
Vadim Zeitlin
204ae594a2 Check that we never get events about switching to State_Idle
This state can never be returned to, once the state becomes active.
2021-01-16 15:02:06 +01:00
Vadim Zeitlin
3241c443c5 Process event about the request becoming active synchronously
This is required in order to allow doing something with the request when
it already have a valid native handle, but hasn't actually started yet.
2021-01-16 14:59:41 +01:00
Vadim Zeitlin
1bf6d5e188 Slightly refactor wxWebRequestImpl::ProcessStateEvent()
Call GetResponse() only once.

Also put the code for State_Completed inside the case for this state in
the switch instead of testing for it separately later.

No real changes.
2021-01-16 14:49:25 +01:00
Vadim Zeitlin
3107a17353 Remove wxWebRequestImpl::IsActiveState()
Semantics of this function wasn't really clear and it was used only
once, so just inline it at the point of use and define better what
happens for various states there.

Also use a switch rather than testing for individual states to make sure
this code is updated if another state is added in the future.

No real changes.
2021-01-16 14:48:47 +01:00
Vadim Zeitlin
a52f353321 Set state to Active slightly earlier in wxWebRequestWinHTTP
This is more consistent with the other backends, which all change the
state before actually launching the asynchronous request.
2021-01-16 14:40:08 +01:00
Vadim Zeitlin
5babe577ce Check that SetState() always actually switches states
We shouldn't call SetState() to switch to the state that we're currently
already in, normally. Add an assert to verify that this indeed doesn't
happen.

Also improve the logging statement to show both the old and the new
states.
2021-01-16 13:50:32 +01:00
Vadim Zeitlin
508a4f6ca8 Fix Cancel() semantics under MSW and other improvements to it
Under MSW, don't set the state to State_Cancelled as soon as Cancel()
was called, as the request was still used from the other threads
afterwards, resulting in race conditions and crashes.

Fix this by just removing the SetState(State_Cancelled) call from the
main thread, as it was redundant anyhow. This also makes the behaviour
correspond to the documentation, which indicates that Cancel() works
asynchronously.

Also ensure, for all backends, that we actually cancel the request only
once, even if public Cancel() is called multiple times. This required
renaming the existing wxWebRequestImpl::Cancel() to DoCancel().
2021-01-16 13:50:29 +01:00
Vadim Zeitlin
b428e531ee Check for errors when calling WinHttpCloseHandle()
Add a trivial wxWinHTTPCloseHandle() wrapper calling wxLogLastError() if
closing the handle failed -- this is really not expected to happen, so
make sure to at least log it if it does.
2021-01-16 13:47:58 +01:00
Vadim Zeitlin
65aad890e3 Add GetNativeHandle() to wxWebSession and wxWebRequest
This allows to retrieve the handles used internally in order to do
something not supported by the public API yet.
2021-01-16 00:21:00 +01:00
Vadim Zeitlin
a561cf199b Remove semi-public wxWebSession::GetImpl()
It's better not to have this method in the public class, even if it
means that we need to pass a wxWebSessionImpl object to wxWebRequestImpl
ctor explicitly now.

No real changes.
2021-01-15 23:50:52 +01:00
Vadim Zeitlin
7677552087 Rename wxWebRequestWinHTTP::m_sessionWinHTTP to m_sessionImpl
No real changes, just use the same name as in the other backends for
consistency (we could also rename m_sessionImpl in the other ones to
m_sessionCURL and m_sessionURLSession respectively, but this would have
been more work and the latter name is really not great).
2021-01-15 23:48:01 +01:00
Vadim Zeitlin
60d429047e Fix workaround for the test failure with Ubuntu 14.04 libcurl
Don't check for 200 status code. Also don't check the response body if
we don't get it at all.
2021-01-15 23:14:14 +01:00
Vadim Zeitlin
af160f3d3e Use CHECK() when REQUIRE() is not needed in wxWebRequest tests
Continue performing the other checks unless we really can't do it.
2021-01-15 15:42:12 +01:00
Vadim Zeitlin
1e8fe318ed Work around wxWebRequest test failure under Ubuntu 14.04
Ignore wrong status code returned by libcurl on this ancient version,
it's not worth dealing with it.
2021-01-15 15:40:32 +01:00
Vadim Zeitlin
420160f0a2 Fix format specifier for DWORD in wxWebRequestWinHTTP code
This fixes assertion failure when running under Win64 due to the size
mismatch between DWORD and size_t on this platform.
2021-01-15 13:00:19 +01:00
Vadim Zeitlin
ef08d499ce Remove unnecessary SetIgnoreServerErrorStatus() from the API
It's up to the application code to decide how it handles the HTTP status
codes it gets back from server, there is no need to have a special
method for handling them in wxWebRequest itself.

We also shouldn't skip downloading the response body just because it was
unsuccessful, we may still need it (e.g. it's very common to return the
detailed error description in a JSON object in the message body when
returning some 4xx error), so don't do it in wxMSW implementation and
add a test verifying that we still get the expected body even for an
error status.

Also improve wxWebRequest::State values documentation.
2021-01-15 03:08:18 +01:00
Vadim Zeitlin
bafbcfa90f Add tracing statements to WinHTTP code too
This again can be very useful for debugging.
2021-01-15 02:56:45 +01:00
Vadim Zeitlin
798d2bb080 Accept everything instead of nothing in wxWebRequestWinHTTP
This is consistent with the other implementations and generally makes
more sense.
2021-01-15 02:54:30 +01:00
Vadim Zeitlin
f85f716cea Show more information about the request result in manual test
Show the HTTP status as well as data retrieved by the server.
2021-01-15 02:52:15 +01:00
Vadim Zeitlin
f9d7a06c37 Fix tags for WebRequest::Manual() unit test
Don't give it any tags other than "." as we don't want to execute it
when these tags are specified, only when it's explicitly selected by
using its name on the command line.
2021-01-15 00:56:49 +01:00
Vadim Zeitlin
168408620d Add wxWebRequest::Cancel() unit test
Check that the request does get cancelled and has the correct state.
2021-01-15 00:53:45 +01:00
Vadim Zeitlin
4e1bece87e Fix end state of cancelled requests in Mac implementation
Don't set the state to State_Failed if the request was cancelled.
2021-01-15 00:53:21 +01:00
Vadim Zeitlin
70e7861a7d Implement authentication support for wxWebRequest under Mac
Add wxWebAuthChallengeURLSession and use the appropriate delegate
callback to create it.
2021-01-15 00:46:45 +01:00
Vadim Zeitlin
e80b65b132 Add timeout to wxWebRequest test
Ensure that the test terminates even if we don't get the expected event.
2021-01-15 00:45:54 +01:00
Vadim Zeitlin
d2840d2516 Add some wxLogTrace() calls to wxWebRequestURLSession code
This is helpful when trying to understand what is going on, especially
because CFNETWORK_DIAGNOSTICS, which is supposed to do the same thing at
native level, doesn't seem to work (at least under 10.14).
2021-01-13 02:04:13 +01:00
Vadim Zeitlin
0ccc6d4047 Remove useless wxWebAuthChallengeCURL::Init()
This just always returned true, so simply remove it to simplify the
code.
2021-01-12 19:15:37 +01:00
Vadim Zeitlin
5e8a14ff41 Update dialogs sample to use wxWebCredentials too
This should have been done in abcc31c6b2 (Update wxCredentialEntryDialog
to use wxWebCredentials, 2021-01-10).
2021-01-12 14:59:14 +01:00
Vadim Zeitlin
ea3d25336c Fix typo in WXWEBREQUEST_BACKEND documentation
Thanks codespell.
2021-01-12 14:53:24 +01:00
Vadim Zeitlin
3f783b15f0 Add another explicit conversion from wxString to "const wchar_t*"
Fix build in wxUSE_STL=1 configuration.
2021-01-12 14:52:14 +01:00
Vadim Zeitlin
20a3317839 Rename wxWebRequestEvent::GetResponseFileName() to GetDataFile()
This is shorter and doesn't imply that just the name (and not the full
path) is being returned.

Also rename wxWebResponse::GetFileName() to GetDataFile() for the same
reasons and for consistency. And document this previously undocumented
method.
2021-01-12 03:34:40 +01:00
Vadim Zeitlin
d0f56b1d04 Document wxWebResponse::GetContentLength()
Also change its return type from wxInt64 to wxFileOffset for consistency
with all the other length/progress-related functions in wxWebRequest.
2021-01-12 03:25:16 +01:00
Vadim Zeitlin
3da03b3b7b Clarify values returned by wxWebRequest progress methods
Make it clear which values change and which remain constant.
2021-01-12 03:14:18 +01:00
Vadim Zeitlin
a1e0b7e292 Slightly simplify code removing temporary file
There is no need to check the state and storage type again when we had
just done it.
2021-01-12 03:09:56 +01:00
Vadim Zeitlin
67ad831a31 Improve documentation of wxWebRequest storage methods
Indicate which methods should be used with each storage type to process
the data later.
2021-01-12 03:09:51 +01:00
Vadim Zeitlin
591d02c979 Increase default buffer size for wxWebRequest operations
Use 64KiB rather than 8KiB, as the latter seems rather small nowadays.

Also add a symbolic constant for this number.
2021-01-12 03:00:35 +01:00
Vadim Zeitlin
6c1e1164d9 Remove unnecessary cast to "void*"
No real changes.
2021-01-12 02:57:30 +01:00
Vadim Zeitlin
646d8014ec Check if specified HTTP method is incompatible with posting data
Currently data can be used with POST or PUT HTTP methods only.
2021-01-12 02:54:13 +01:00
Vadim Zeitlin
7af2f29602 Use more readable CmpNoCase() in wxWebRequestCURL code
No real changes, just make case-insensitive comparisons more clear.
2021-01-12 02:52:28 +01:00
Vadim Zeitlin
9a8981241e Check return value of curl_easy_init()
Normally it is not supposed to fail, but still try not to crash if it
does.
2021-01-12 02:49:51 +01:00
Vadim Zeitlin
468a961426 Rename methods called from libcurl to use more clear names
Indicate that they're callbacks used by libcurl rather than normal
methods used by the application code itself.

No real changes.
2021-01-12 02:40:38 +01:00
Vadim Zeitlin
228d231753 Avoid copying POST data in NSURLSession wxWebRequest code
Just give the ownership of the buffer to NSData instead of copying it.
2021-01-12 02:34:18 +01:00
Vadim Zeitlin
5713d17ab0 Clarify asynchronous nature of wxWebRequest::Cancel() in the docs 2021-01-12 02:30:33 +01:00
Vadim Zeitlin
dceb24ad7c Add support for WXWEBREQUEST_BACKEND environment variable
Defining this variable overrides the default backend choice.

Document the variable itself and also extend wxWebSession::New()
documentation.
2021-01-12 02:17:39 +01:00
Vadim Zeitlin
d3b93a48b3 Remove wxWebSessionBackendDefault and just use empty string
There doesn't seem to be any reason to have this constant, so don't
define it and just interpret empty value of backend as meaning to choose
the default one in wxWebSession::New().
2021-01-12 02:17:31 +01:00
Vadim Zeitlin
3b87af5738 Fix the build when implicit wxString conversions are disabled
This corrects a bug introduced in 5d256988be (Add wxMSWFormatMessage()
and use it from other places, 2021-01-09).
2021-01-11 14:18:42 +01:00