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

add path for parser

parent 431a021e
No related branches found
No related tags found
1 merge request!19Resolve "use multi curl to improve performance"
...@@ -140,6 +140,12 @@ class ProxyController extends Controller ...@@ -140,6 +140,12 @@ class ProxyController extends Controller
$targetUrl = str_replace("<<SLASH>>", "/", $url); $targetUrl = str_replace("<<SLASH>>", "/", $url);
$targetUrl = str_rot13(base64_decode($targetUrl)); $targetUrl = str_rot13(base64_decode($targetUrl));
try{
$path = parse_url($targetUrl)["path"];
}catch(\Exception $e){
$path = "";
}
$this->password = $password; $this->password = $password;
// Hash Value under which a possible cached file would've been stored // Hash Value under which a possible cached file would've been stored
...@@ -171,7 +177,7 @@ class ProxyController extends Controller ...@@ -171,7 +177,7 @@ class ProxyController extends Controller
} else { } else {
$answer = Cache::get($hash); $answer = Cache::get($hash);
} }
$result = HttpParser::parse($answer); $result = HttpParser::parse($answer, $path);
if ($result === null) { if ($result === null) {
return $this->streamFile($targetUrl); return $this->streamFile($targetUrl);
} else { } else {
......
...@@ -5,7 +5,7 @@ namespace app\Models; ...@@ -5,7 +5,7 @@ namespace app\Models;
class HttpParser class HttpParser
{ {
public static function parseHeader($headerPart){ public static function parseHeader($headerPart, $path = "") {
$headerLine = explode("\r\n", $headerPart); $headerLine = explode("\r\n", $headerPart);
$httpcode = rtrim($headerLine[0]); $httpcode = rtrim($headerLine[0]);
$httpcode = explode(" ", $httpcode); $httpcode = explode(" ", $httpcode);
...@@ -16,13 +16,21 @@ class HttpParser ...@@ -16,13 +16,21 @@ class HttpParser
$header[$tmp[0]] = $tmp[1]; $header[$tmp[0]] = $tmp[1];
} }
} }
if(!isset($header['content-type'])){ if(!isset($header['content-type'])) {
$header['content-type'] = 'application/octet-stream'; if(substr($path, -4) === '.css') {
$header['content-type'] = 'text/css';
} elseif(substr($path, -3) === '.js') {
$header['content-type'] = 'text/javascript';
} elseif(substr($path, -4) === '.svg') {
$header['content-type'] = 'image/svg+xml';
} else {
$header['content-type'] = 'application/octet-stream';
}
} }
return $header; return $header;
} }
public static function parse($htmldoc){ public static function parse($htmldoc, $path = "") {
try{ try{
$parts = explode("\r\n\r\n", $htmldoc); $parts = explode("\r\n\r\n", $htmldoc);
$regex = "/^HTTP/sm"; $regex = "/^HTTP/sm";
...@@ -33,7 +41,7 @@ class HttpParser ...@@ -33,7 +41,7 @@ class HttpParser
} }
$i++; $i++;
} }
$out['header'] = self::parseHeader($parts[$i-1]); $out['header'] = self::parseHeader($parts[$i-1], $path);
$out['data'] = implode(array_slice($parts,$i)); $out['data'] = implode(array_slice($parts,$i));
unset($out['header']['content-encoding']); unset($out['header']['content-encoding']);
unset($out['header']['content-length']); unset($out['header']['content-length']);
......
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