URIReader: Allow overriding user agent through public member variable, fix for readAll() deadlock

This commit is contained in:
Thulinma 2020-10-27 17:21:05 +01:00
parent fff4e2b3d4
commit b9c03ccb18
2 changed files with 8 additions and 2 deletions

View file

@ -103,6 +103,7 @@ namespace HTTP{
// Send HEAD request to determine range request is supported, and get total length
downer.clearHeaders();
if (userAgentOverride.size()){downer.setHeader("User-Agent", userAgentOverride);}
if (!downer.head(myURI) || !downer.isOk()){
FAIL_MSG("Error getting URI info for '%s': %" PRIu32 " %s", myURI.getUrl().c_str(),
downer.getStatusCode(), downer.getStatusText().c_str());
@ -170,7 +171,10 @@ namespace HTTP{
/// Read all blocking function, which internally uses the Nonblocking function.
void URIReader::readAll(char *&dataPtr, size_t &dataLen){
if (getSize() != std::string::npos){allData.allocate(getSize());}
while (!isEOF()){readSome(10046, *this);}
while (!isEOF()){
readSome(10046, *this);
bufPos = allData.size();
}
dataPtr = allData;
dataLen = allData.size();
}
@ -205,7 +209,7 @@ namespace HTTP{
curPos += dataLen;
}else if (stateType == HTTP::HTTP){
bool res = downer.continueNonBlocking(cb);
downer.continueNonBlocking(cb);
curPos = downer.const_data().size();
}else{// streaming mode
int s;

View file

@ -62,6 +62,8 @@ namespace HTTP{
void (*httpBodyCallback)(const char *ptr, size_t size);
void dataCallback(const char *ptr, size_t size);
std::string userAgentOverride;
private:
// Internal state variables
bool (*cbProgress)(uint8_t); ///< The progress callback, if any. Not called if set to a null pointer.