Store the MIME type in HTTPResourceRequest::onRequestFinished()

This commit is contained in:
sabrina-shanman 2018-11-15 14:52:27 -08:00
parent fc0a31fa0d
commit 2387641cbb
2 changed files with 22 additions and 1 deletions

View file

@ -94,7 +94,7 @@ void HTTPResourceRequest::onRequestFinished() {
// Content-Range: <unit> <range-start>-<range-end>/*
// Content-Range: <unit> */<size>
//
auto parseContentRangeHeader = [](QString contentRangeHeader) -> std::pair<bool, uint64_t> {
static auto parseContentRangeHeader = [](QString contentRangeHeader) -> std::pair<bool, uint64_t> {
auto unitRangeParts = contentRangeHeader.split(' ');
if (unitRangeParts.size() != 2) {
return { false, 0 };
@ -115,6 +115,15 @@ void HTTPResourceRequest::onRequestFinished() {
}
};
static auto parseMediaType = [](QString contentTypeHeader) -> std::pair<bool, QString> {
auto contentTypeParts = contentTypeHeader.split(';');
if (contentTypeParts.size() < 1) {
return { false, "" };
}
return { true, contentTypeParts[0] };
};
switch(_reply->error()) {
case QNetworkReply::NoError:
_data = _reply->readAll();
@ -141,6 +150,16 @@ void HTTPResourceRequest::onRequestFinished() {
}
}
{
auto contentTypeHeader = _reply->rawHeader("Content-Type");
bool success;
QString mediaType;
std::tie(success, mediaType) = parseMediaType(contentTypeHeader);
if (success) {
_webMediaType = mediaType;
}
}
recordBytesDownloadedInStats(STAT_HTTP_RESOURCE_TOTAL_BYTES, _data.size());
break;

View file

@ -84,6 +84,7 @@ public:
bool loadedFromCache() const { return _loadedFromCache; }
bool getRangeRequestSuccessful() const { return _rangeRequestSuccessful; }
bool getTotalSizeOfResource() const { return _totalSizeOfResource; }
QString getWebMediaType() const { return _webMediaType; }
void setFailOnRedirect(bool failOnRedirect) { _failOnRedirect = failOnRedirect; }
void setCacheEnabled(bool value) { _cacheEnabled = value; }
@ -111,6 +112,7 @@ protected:
ByteRange _byteRange;
bool _rangeRequestSuccessful { false };
uint64_t _totalSizeOfResource { 0 };
QString _webMediaType;
int64_t _lastRecordedBytesDownloaded { 0 };
bool _isObservable;
qint64 _callerId;