Skip to content
Snippets Groups Projects
Commit 04be664f authored by Davide Aprea's avatar Davide Aprea
Browse files

add correct charset to http header

parent feca5f9f
No related branches found
No related tags found
1 merge request!19Resolve "use multi curl to improve performance"
...@@ -8,6 +8,7 @@ class HtmlDocument extends Document ...@@ -8,6 +8,7 @@ class HtmlDocument extends Document
{ {
private $htmlString; private $htmlString;
private $encoding;
public function __construct($password, $baseUrl, $htmlString, $encoding) public function __construct($password, $baseUrl, $htmlString, $encoding)
{ {
...@@ -30,7 +31,7 @@ class HtmlDocument extends Document ...@@ -30,7 +31,7 @@ class HtmlDocument extends Document
if ($meta->hasAttribute("http-equiv") && strtolower($meta->getAttribute("http-equiv")) === "content-type" && $meta->hasAttribute("content")) { if ($meta->hasAttribute("http-equiv") && strtolower($meta->getAttribute("http-equiv")) === "content-type" && $meta->hasAttribute("content")) {
$contentType = $meta->getAttribute("content"); $contentType = $meta->getAttribute("content");
$encoding = stripos($contentType, "charset=") !== false ? trim(substr($contentType, stripos($contentType, "charset=") + 8)) : null; $encoding = stripos($contentType, "charset=") !== false ? trim(substr($contentType, stripos($contentType, "charset=") + 8)) : null;
$contentEncoding = rtrim($contentEncoding, ";"); $encoding = rtrim($encoding, ";");
if ($encoding !== null) { if ($encoding !== null) {
break; break;
} }
...@@ -48,6 +49,7 @@ class HtmlDocument extends Document ...@@ -48,6 +49,7 @@ class HtmlDocument extends Document
# Default Fallback # Default Fallback
} }
if (!empty($encoding)) { if (!empty($encoding)) {
$this->encoding = $encoding;
return mb_convert_encoding($htmlString, 'HTML-ENTITIES', $encoding); return mb_convert_encoding($htmlString, 'HTML-ENTITIES', $encoding);
} else { } else {
return mb_convert_encoding($htmlString, 'HTML-ENTITIES'); return mb_convert_encoding($htmlString, 'HTML-ENTITIES');
...@@ -59,6 +61,11 @@ class HtmlDocument extends Document ...@@ -59,6 +61,11 @@ class HtmlDocument extends Document
return $this->htmlString; return $this->htmlString;
} }
public function getEncoding()
{
return $this->encoding;
}
/** /**
* Function proxifyContent * Function proxifyContent
* This method parses the given String and Proxifies all Links/Urls in it so it's targetting this Proxy Server * This method parses the given String and Proxifies all Links/Urls in it so it's targetting this Proxy Server
......
...@@ -205,6 +205,7 @@ class ProxyController extends Controller ...@@ -205,6 +205,7 @@ class ProxyController extends Controller
# It's an html document # It's an html document
$htmlDocument = new HtmlDocument($password, $targetUrl, $result["data"], $contentEncoding); $htmlDocument = new HtmlDocument($password, $targetUrl, $result["data"], $contentEncoding);
$htmlDocument->proxifyContent(); $htmlDocument->proxifyContent();
$result['header']['content-type'] = $contentType . "; charset=" . $htmlDocument->getEncoding();
$result["data"] = $htmlDocument->getResult(); $result["data"] = $htmlDocument->getResult();
break; break;
case 'application/pdf': case 'application/pdf':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment