Commit Graph

46 Commits

Author SHA1 Message Date
Tobias Taschner
457b213315 Apply suggestions from code review
Co-authored-by: VZ <vz-github@zeitlins.org>
2021-01-19 21:06:31 +01:00
Tobias Taschner
036b7f29a7 Add wxWebRequest::DisablePeerVerify()
This method allows insecure HTTPS connections when required
2021-01-19 13:16:25 +01:00
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
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
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
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
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
000856a342 Make wxWebCredentials available even when wxUSE_WEBREQUEST==0
This fixed build with wxUSE_CREDENTIALDLG==1 but wxUSE_WEBREQUEST==0.

No real changes, this commit just moves the code around.
2021-01-11 03:16:21 +01:00
Vadim Zeitlin
4986850c63 Rename wxWebSession::SetHeader() to AddCommonHeader()
The old name wasn't very clear and it was confusing to have methods with
the same name in wxWebSession and wxWebRequest.
2021-01-11 03:02:25 +01:00
Vadim Zeitlin
abcc31c6b2 Update wxCredentialEntryDialog to use wxWebCredentials
As a side effect, make wxWebCredentials default-constructible.

Also demonstrate using wxCredentialEntryDialog in the sample.
2021-01-10 21:27:15 +01:00
Vadim Zeitlin
1e6d6be8bb Add wxWebCredentials and use it in SetCredentials()
Prefer using a class encapsulating both the user name and the password
to using a pair of variables.
2021-01-10 21:27:15 +01:00
Vadim Zeitlin
6e546a3d4b Don't use wxSharedPtr<> in factory registration code
Shared ownership semantics again seems inappropriate here as we're not
actually sharing the pointers here, so just use raw pointers instead
(with C++11 we could use std::unique_ptr<>, but this is impossible with
our own map and scoped pointer implementations).

No real changes.
2021-01-04 02:06:10 +01:00
Vadim Zeitlin
989cafe535 Take raw pointer and not wxSharedPtr<> in SetData()
Using shared pointer seems to be ill-advised here, the stream shouldn't
be shared as it's going to be used by wxWebRequest itself and can't be
used by the application code in parallel, so the ownership transfer
semantics is more appropriate.

We could take a wxScopedPtr<> instead, but wx API takes ownership of raw
pointers everywhere else, so do it here too.

Incidentally fix a bug with calling IsOk() on a possibly null pointer.
2021-01-04 01:57:36 +01:00
Vadim Zeitlin
50424cba2c Change wxWebRequest and related objects to hide ref counting
Don't force the application code to deal with wxObjectDataPtr<> or,
worse, calling {Inc,Dec}Ref() manually by hiding it inside the wx
objects themselves and giving the value-like semantics to them.

There should be no real changes in the behaviour, but the API does
change significantly. Notably, wxWebRequest is not a wxEvtHandler itself
any longer, as this would be incompatible with the value semantics, and
an event handler needs to be specified when creating it, so that it
could be notified about the request state changes.
2020-12-30 02:02:20 +01:00
Vadim Zeitlin
be5f1344b6 Add some comments describing wxWebSession methods
No real changes.
2020-12-27 13:01:49 +01:00
Vadim Zeitlin
71d5729171 Make wxWebSessionFactory private
Having wxWebSessionFactory part of the public API implies keeping
compatibility with the possible ways of implementing it which is too
restrictive for no good reason, so move this class to the private header
and don't document it nor wxWebSession::RegisterFactory() (which is now
private).
2020-12-27 01:03:08 +01:00
Vadim Zeitlin
59bc7e59d7 Get rid of public wxWebSession::GetHeaders()
This is unnecessary, it can be protected and we can initialize
wxWebRequest::m_headers directly in its ctor instead of using this
function (which also simplifies code and makes it impossible to forget
to do this).
2020-12-13 03:09:55 +01:00
Vadim Zeitlin
b37c7417f6 Don't make wxWebRequest::SplitParameters() public
They're not necessary to use this class and we may consider exporting
them later, possibly with a better API and more tests, if really needed.

Also do change their API slightly by leaving only a single function and
returning the value instead of using an out parameter for it to make it
simpler to use.
2020-12-13 02:41:01 +01:00
Vadim Zeitlin
ea71cf3984 Include wx/hashmap.h from wx/webrequest.h explicitly
This header was already implicitly included, but make it explicit.

No real changes.
2020-12-13 02:28:25 +01:00
Vadim Zeitlin
fc633f5aae Move wxStringWebSessionFactoryMap out of the header
Define wxWebSession::ms_defaultSession and ms_factoryMap in the
implementation file to avoid having to make the otherwise unnecessary
wxStringWebSessionFactoryMap type public.

No real changes.
2020-12-13 02:24:43 +01:00
Vadim Zeitlin
8ea4f38689 Make wxWebResponse::Init() and Finalize() non-public
The former can be called from the derived class ctors while the latter
only needs to be called from wxWebRequest itself, so just make it a
friend: this is not ideal, but still better than leaving this public and
simpler than any alternatives.
2020-12-13 01:33:01 +01:00
Vadim Zeitlin
1c61fe6baf Remove wxWebResponse::AsString() conversion parameter
It doesn't make much sense to specify the conversion here, it would
ideally be taken from the response Content-Type header itself and
currently is just assumed to be UTF-8 anyhow.

Also implement fallback to Latin-1 to avoid losing the data entirely if
it's not in UTF-8.
2020-12-13 01:16:41 +01:00
Vadim Zeitlin
204645a47c Initialize all fields in wxWebRequestEvent default ctor
Default ctor was leaving pointers uninitialized which was dangerous, so
merge it with the other ctor to ensure that we always set them to NULL.

Also make m_response const as it can't be changed after creating the
event.
2020-12-13 00:48:23 +01:00
Vadim Zeitlin
0c9f4ababa Document wxWebResponse pointers as being non-owning
wxWebResponse objects belong to wxWebRequest itself.
2020-12-13 00:47:53 +01:00
Vadim Zeitlin
727b590814 Pass wxSharedPtr argument of RegisterFactory() by const reference
Avoid extra copies from passing it by value.
2020-12-13 00:19:03 +01:00
Vadim Zeitlin
64a3801160 Tweaks to wxWebRequest::SetData() overload taking stream
Check that the stream is valid, if specified at all, and return false if
it isn't -- or if no size was specified and determining stream size
failed.

Check for SetData() success in the test to provide better diagnostics in
case the file it uses is not found (as is the case when running the test
from another directory, for example).

Also pass wxSharedPtr<> by const reference instead of by value to avoid
unnecessary copies.
2020-12-12 18:46:28 +01:00
Tobias Taschner
45f006d752 Add wxWebSession::GetLibraryVersionInfo() 2018-12-10 19:38:12 +01:00
Tobias Taschner
7577c95aab Destroy default wxWebSession in module 2018-12-10 19:38:05 +01:00
Tobias Taschner
f04094e4ec Implement GetBytesReceived() in base class 2018-12-10 19:38:04 +01:00
Tobias Taschner
ab544da1d2 Move GetBytesExpectedToReceive() impl to base class 2018-12-10 19:38:03 +01:00
Tobias Taschner
f40e2e64d9 Add wxWebRequest::SplitParameters method
This method is adapted for use in wxWidgets from the Poco library.
2018-12-10 19:37:55 +01:00
Tobias Taschner
e6b33cb76c Various small interface changes 2018-12-10 19:37:53 +01:00
Tobias Taschner
56af6cbdee Implement Cancel for WinHTTP backend 2018-12-10 19:37:50 +01:00
Tobias Taschner
c24efa9821 Implement additional storage targets 2018-12-10 19:37:42 +01:00
Tobias Taschner
6530e3c08e Move response data handling to base class 2018-12-10 19:37:40 +01:00
Tobias Taschner
5660565081 Prepare wxWebRequest::SetStorage() implementation 2018-12-10 19:37:39 +01:00
Tobias Taschner
cf85c04d25 Add wxWebRequest progress methods 2018-12-10 19:37:38 +01:00
Tobias Taschner
871049f1a1 Implement wxWebResponse::GetMimeType() and GetSuggestedFileName() 2018-12-10 19:37:37 +01:00
Tobias Taschner
03e9b1b549 Remove progress events 2018-12-10 19:37:35 +01:00
Tobias Taschner
4fd6091513 Implement WinHTTP authentication 2018-12-10 19:37:35 +01:00
Tobias Taschner
701f697fa4 Change wxWebRequest API to use STATE event 2018-12-10 19:37:30 +01:00
Tobias Taschner
d7dee7019e Implement sending request data with wxWebRequest 2018-12-10 19:37:25 +01:00
Tobias Taschner
a4279752f8 Start wxWebRequestWinHTTP implementation
Can already run the GET request in the sample app
2018-12-10 19:37:23 +01:00
Tobias Taschner
e07c1bf40c Prepared wxWebRequest implementation 2018-12-10 19:37:21 +01:00