URIReader: Allow overriding user agent through public member variable, fix for readAll() deadlock
This commit is contained in:
parent
fff4e2b3d4
commit
b9c03ccb18
2 changed files with 8 additions and 2 deletions
|
@ -103,6 +103,7 @@ namespace HTTP{
|
||||||
|
|
||||||
// Send HEAD request to determine range request is supported, and get total length
|
// Send HEAD request to determine range request is supported, and get total length
|
||||||
downer.clearHeaders();
|
downer.clearHeaders();
|
||||||
|
if (userAgentOverride.size()){downer.setHeader("User-Agent", userAgentOverride);}
|
||||||
if (!downer.head(myURI) || !downer.isOk()){
|
if (!downer.head(myURI) || !downer.isOk()){
|
||||||
FAIL_MSG("Error getting URI info for '%s': %" PRIu32 " %s", myURI.getUrl().c_str(),
|
FAIL_MSG("Error getting URI info for '%s': %" PRIu32 " %s", myURI.getUrl().c_str(),
|
||||||
downer.getStatusCode(), downer.getStatusText().c_str());
|
downer.getStatusCode(), downer.getStatusText().c_str());
|
||||||
|
@ -170,7 +171,10 @@ namespace HTTP{
|
||||||
/// Read all blocking function, which internally uses the Nonblocking function.
|
/// Read all blocking function, which internally uses the Nonblocking function.
|
||||||
void URIReader::readAll(char *&dataPtr, size_t &dataLen){
|
void URIReader::readAll(char *&dataPtr, size_t &dataLen){
|
||||||
if (getSize() != std::string::npos){allData.allocate(getSize());}
|
if (getSize() != std::string::npos){allData.allocate(getSize());}
|
||||||
while (!isEOF()){readSome(10046, *this);}
|
while (!isEOF()){
|
||||||
|
readSome(10046, *this);
|
||||||
|
bufPos = allData.size();
|
||||||
|
}
|
||||||
dataPtr = allData;
|
dataPtr = allData;
|
||||||
dataLen = allData.size();
|
dataLen = allData.size();
|
||||||
}
|
}
|
||||||
|
@ -205,7 +209,7 @@ namespace HTTP{
|
||||||
curPos += dataLen;
|
curPos += dataLen;
|
||||||
|
|
||||||
}else if (stateType == HTTP::HTTP){
|
}else if (stateType == HTTP::HTTP){
|
||||||
bool res = downer.continueNonBlocking(cb);
|
downer.continueNonBlocking(cb);
|
||||||
curPos = downer.const_data().size();
|
curPos = downer.const_data().size();
|
||||||
}else{// streaming mode
|
}else{// streaming mode
|
||||||
int s;
|
int s;
|
||||||
|
|
|
@ -62,6 +62,8 @@ namespace HTTP{
|
||||||
void (*httpBodyCallback)(const char *ptr, size_t size);
|
void (*httpBodyCallback)(const char *ptr, size_t size);
|
||||||
void dataCallback(const char *ptr, size_t size);
|
void dataCallback(const char *ptr, size_t size);
|
||||||
|
|
||||||
|
std::string userAgentOverride;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Internal state variables
|
// Internal state variables
|
||||||
bool (*cbProgress)(uint8_t); ///< The progress callback, if any. Not called if set to a null pointer.
|
bool (*cbProgress)(uint8_t); ///< The progress callback, if any. Not called if set to a null pointer.
|
||||||
|
|
Loading…
Add table
Reference in a new issue