Skip to content

Commit

Permalink
Merge pull request #1216 from xiaoyifang/opt/206-response
Browse files Browse the repository at this point in the history
fix: reduce 206 response
  • Loading branch information
xiaoyifang authored Oct 9, 2023
2 parents 3ab2d10 + e3f6a28 commit c3df1dc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,12 @@ qint64 ArticleResourceReply::bytesAvailable() const
if ( avail < 0 )
return 0;

if ( !req->isFinished() ) {
return 65536;
qint64 availBytes = avail - alreadyRead + QNetworkReply::bytesAvailable();
if ( availBytes == 0 && !req->isFinished() ) {
return 10240;
}

return avail - alreadyRead + QNetworkReply::bytesAvailable();
return availBytes;
}


Expand Down
3 changes: 2 additions & 1 deletion src/common/globalregex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ QRegularExpression Ftx::token( R"((".*?")|([\w\W\+\-]+))",
| QRegularExpression::CaseInsensitiveOption );
//mdx
QRegularExpression Mdx::allLinksRe( R"((?:<\s*(a(?:rea)?|img|link|script|source)(?:\s+[^>]+|\s*)>))",
//<audio src="xxx"> is also a valid url.
QRegularExpression Mdx::allLinksRe( R"((?:<\s*(a(?:rea)?|img|link|script|source|audio|video)(?:\s+[^>]+|\s*)>))",
QRegularExpression::CaseInsensitiveOption );
QRegularExpression Mdx::wordCrossLink( R"(([\s"']href\s*=)\s*(["'])entry://([^>#]*?)((?:#[^>]*?)?)\2)",
QRegularExpression::CaseInsensitiveOption );
Expand Down
12 changes: 7 additions & 5 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
QString linkType = allLinksMatch.captured( 1 ).toLower();
QString newLink;

if ( !linkType.isEmpty() && linkType.at( 0 ) == 'a' ) {
if ( linkType.compare( "a" ) == 0 || linkType.compare( "area" ) == 0 ) {
newLink = linkTxt;

QRegularExpressionMatch match = RX::Mdx::audioRe.match( newLink );
Expand Down Expand Up @@ -956,12 +956,12 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
else
newLink = linkTxt.replace( RX::Mdx::stylesRe2, R"(\1"bres://)" + id + R"(/\2")" );
}
else if ( linkType.compare( "script" ) == 0 || linkType.compare( "img" ) == 0
|| linkType.compare( "source" ) == 0 ) {
else {
//linkType in ("script","img","source","audio","video")
// javascripts and images
QRegularExpressionMatch match = RX::Mdx::inlineScriptRe.match( linkTxt );
if ( linkType.at( 1 ) == 'c' // "script" tag
&& match.hasMatch() && match.capturedLength() == linkTxt.length() ) {
// "script" tag
if ( linkType.compare( "script" ) == 0 && match.hasMatch() && match.capturedLength() == linkTxt.length() ) {
// skip inline scripts
articleNewText += linkTxt;
match = RX::Mdx::closeScriptTagRe.match( article, linkPos );
Expand All @@ -972,6 +972,7 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
continue;
}
else {
//audio ,video ,html5 tags fall here.
match = RX::Mdx::srcRe.match( linkTxt );
if ( match.hasMatch() ) {
QString newText;
Expand All @@ -992,6 +993,7 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
newLink = linkTxt.replace( RX::Mdx::srcRe2, R"(\1"bres://)" + id + R"(/\2")" );
}
}

if ( !newLink.isEmpty() ) {
articleNewText += newLink;
}
Expand Down

0 comments on commit c3df1dc

Please sign in to comment.