Skip to content

Commit 6e44509

Browse files
committed
Fixed bug concerning upload data length
1 parent 3f15cd1 commit 6e44509

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

NetworkClient.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ struct CurlInitializer {
191191
curl_global_cleanup();
192192
}
193193
};
194-
195194
}
196195

197196
NetworkClient::NetworkClient():
@@ -211,7 +210,7 @@ NetworkClient::NetworkClient():
211210
{
212211
static NetworkClientInternal::CurlInitializer initializer;
213212

214-
*m_errorBuffer = 0;
213+
*errorBuffer_ = 0;
215214
curlHandle_ = curl_easy_init();
216215
bodyFuncData_.funcType = funcTypeBody;
217216
bodyFuncData_.nmanager = this;
@@ -225,7 +224,7 @@ NetworkClient::NetworkClient():
225224
curl_easy_setopt(curlHandle_, CURLOPT_WRITEFUNCTION, private_static_writer);
226225
curl_easy_setopt(curlHandle_, CURLOPT_WRITEDATA, &bodyFuncData_);
227226
curl_easy_setopt(curlHandle_, CURLOPT_WRITEHEADER, &headerFuncData_);
228-
curl_easy_setopt(curlHandle_, CURLOPT_ERRORBUFFER, m_errorBuffer);
227+
curl_easy_setopt(curlHandle_, CURLOPT_ERRORBUFFER, errorBuffer_);
229228

230229
curl_easy_setopt(curlHandle_, CURLOPT_PROGRESSFUNCTION, &private_progress_func);
231230
curl_easy_setopt(curlHandle_, CURLOPT_NOPROGRESS, 0L);
@@ -340,7 +339,7 @@ size_t NetworkClient::private_progress_func(void* clientp, double dltotal, doubl
340339
}
341340

342341
void NetworkClient::setMethod(const NString& str) {
343-
m_method = str;
342+
method_ = str;
344343
}
345344

346345
void NetworkClient::addQueryParam(const NString& name, const NString& value) {
@@ -368,9 +367,10 @@ void NetworkClient::setUrl(const NString& url) {
368367
}
369368

370369
bool NetworkClient::doUploadMultipartData() {
371-
if (m_method.empty()) {
370+
if (method_.empty()) {
372371
setMethod("POST");
373372
}
373+
374374
private_init_transfer();
375375
private_apply_method();
376376

@@ -486,7 +486,7 @@ NString NetworkClient::urlEncode(const NString& str) {
486486
}
487487

488488
NString NetworkClient::errorString() const {
489-
return m_errorBuffer;
489+
return errorBuffer_;
490490
}
491491

492492
void NetworkClient::setUserAgent(const NString& userAgentStr) {
@@ -575,7 +575,7 @@ void NetworkClient::private_cleanup_after() {
575575
outFile_ = nullptr;
576576
}
577577
outFileName_.clear();
578-
m_method.clear();
578+
method_.clear();
579579
curl_easy_setopt(curlHandle_, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(-1));
580580

581581
uploadData_.clear();
@@ -663,6 +663,7 @@ bool NetworkClient::doUpload(const NString& fileName, const NString& data) {
663663
/*if (m_method != "PUT") {
664664
addQueryHeader("Content-Length", std::to_string(currentUploadDataSize_));
665665
}*/
666+
curl_easy_setopt(curlHandle_, CURLOPT_POSTFIELDSIZE_LARGE, static_cast<curl_off_t>(currentUploadDataSize_));
666667

667668
curl_easy_setopt(curlHandle_, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(currentUploadDataSize_));
668669

@@ -676,14 +677,14 @@ bool NetworkClient::doUpload(const NString& fileName, const NString& data) {
676677
bool NetworkClient::private_apply_method() {
677678
curl_easy_setopt(curlHandle_, CURLOPT_CUSTOMREQUEST,nullptr);
678679
curl_easy_setopt(curlHandle_, CURLOPT_UPLOAD, 0L);
679-
if (m_method == "POST")
680+
if (method_ == "POST")
680681
curl_easy_setopt(curlHandle_, CURLOPT_POST, 1L);
681-
else if (m_method == "GET")
682+
else if (method_ == "GET")
682683
curl_easy_setopt(curlHandle_, CURLOPT_HTTPGET, 1L);
683-
else if (m_method == "PUT")
684+
else if (method_ == "PUT")
684685
curl_easy_setopt(curlHandle_, CURLOPT_UPLOAD, 1L);
685-
else if (!m_method.empty()) {
686-
curl_easy_setopt(curlHandle_, CURLOPT_CUSTOMREQUEST, m_method.c_str());
686+
else if (!method_.empty()) {
687+
curl_easy_setopt(curlHandle_, CURLOPT_CUSTOMREQUEST, method_.c_str());
687688
} else {
688689
curl_easy_setopt(curlHandle_, CURLOPT_CUSTOMREQUEST, nullptr);
689690
return false;

NetworkClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ class NetworkClient
182182
std::string internalBuffer_;
183183
std::string headerBuffer_;
184184
NString userAgent_;
185-
char m_errorBuffer[CURL_ERROR_SIZE];
186-
std::string m_method;
185+
char errorBuffer_[CURL_ERROR_SIZE];
186+
std::string method_;
187187
struct curl_slist* chunk_;
188188
int64_t chunkOffset_;
189189
int64_t chunkSize_;

0 commit comments

Comments
 (0)