NETWORKING: Properly process TLS errors.
Now, when HTTPS is not supported, we will indicate it to the user.
This commit is contained in:
parent
938212c6f1
commit
a670a17480
3 changed files with 27 additions and 6 deletions
|
@ -193,19 +193,19 @@ void NetworkReadStream::setupFormMultipart(Common::HashMap<Common::String, Commo
|
|||
}
|
||||
|
||||
NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading, bool usingPatch, bool keepAlive, long keepAliveIdle, long keepAliveInterval):
|
||||
_backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr) {
|
||||
_backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr), _errorCode(CURLE_OK) {
|
||||
initCurl(url, headersList);
|
||||
setupBufferContents((const byte *)postFields.c_str(), postFields.size(), uploading, usingPatch, false);
|
||||
}
|
||||
|
||||
NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles, bool keepAlive, long keepAliveIdle, long keepAliveInterval):
|
||||
_backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr) {
|
||||
_backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr), _errorCode(CURLE_OK) {
|
||||
initCurl(url, headersList);
|
||||
setupFormMultipart(formFields, formFiles);
|
||||
}
|
||||
|
||||
NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post, bool keepAlive, long keepAliveIdle, long keepAliveInterval):
|
||||
_backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr) {
|
||||
_backingStream(DisposeAfterUse::YES), _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval), _errorBuffer(nullptr), _errorCode(CURLE_OK) {
|
||||
initCurl(url, headersList);
|
||||
setupBufferContents(buffer, bufferSize, uploading, usingPatch, post);
|
||||
}
|
||||
|
@ -266,14 +266,23 @@ void NetworkReadStream::finished(uint32 errorCode) {
|
|||
char *url = nullptr;
|
||||
curl_easy_getinfo(_easy, CURLINFO_EFFECTIVE_URL, &url);
|
||||
|
||||
if (errorCode == CURLE_OK) {
|
||||
_errorCode = errorCode;
|
||||
|
||||
if (_errorCode == CURLE_OK) {
|
||||
debug(9, "NetworkReadStream: %s - Request succeeded", url);
|
||||
} else {
|
||||
warning("NetworkReadStream: %s - Request failed (%d - %s)", url, errorCode,
|
||||
strlen(_errorBuffer) ? _errorBuffer : curl_easy_strerror((CURLcode)errorCode));
|
||||
warning("NetworkReadStream: %s - Request failed (%d - %s)", url, _errorCode, getError());
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkReadStream::hasError() const {
|
||||
return _errorCode != CURLE_OK;
|
||||
}
|
||||
|
||||
const char *NetworkReadStream::getError() const {
|
||||
return strlen(_errorBuffer) ? _errorBuffer : curl_easy_strerror((CURLcode)_errorCode);
|
||||
}
|
||||
|
||||
long NetworkReadStream::httpResponseCode() const {
|
||||
long responseCode = -1;
|
||||
if (_easy)
|
||||
|
|
|
@ -40,6 +40,7 @@ class NetworkReadStream: public Common::ReadStream {
|
|||
long _keepAliveIdle, _keepAliveInterval;
|
||||
bool _eos, _requestComplete;
|
||||
char *_errorBuffer;
|
||||
uint32 _errorCode;
|
||||
const byte *_sendingContentsBuffer;
|
||||
uint32 _sendingContentsSize;
|
||||
uint32 _sendingContentsPos;
|
||||
|
@ -168,6 +169,11 @@ public:
|
|||
void setProgress(uint64 downloaded, uint64 total);
|
||||
|
||||
bool keepAlive() const { return _keepAlive; }
|
||||
|
||||
bool hasError() const;
|
||||
uint32 getErrorCode() const { return _errorCode; }
|
||||
const char *getError() const;
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace Networking
|
||||
|
|
|
@ -183,6 +183,12 @@ void SessionRequest::handle() {
|
|||
}
|
||||
|
||||
if (_stream->eos()) {
|
||||
if (_stream->hasError()) {
|
||||
ErrorResponse error(this, false, true, Common::String::format("TLS stream response code is not CURLE_OK OK: %s", _stream->getError()), _stream->getErrorCode());
|
||||
finishError(error);
|
||||
return;
|
||||
}
|
||||
|
||||
finishSuccess();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue