avoids caching 'maven-metadata.xml*' and '*-SNAPSHOT*', avoids delivering already stored files of the same
This commit is contained in:
parent
225ae1f92a
commit
bfd00d2608
2 changed files with 50 additions and 13 deletions
|
@ -1,3 +1,5 @@
|
|||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-f [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} =maven-metadata.xml [OR]
|
||||
RewriteCond %{REQUEST_URI} -SNAPSHOT
|
||||
RewriteRule ^.*$ src/mvncache.php [L]
|
||||
|
|
|
@ -26,6 +26,25 @@ foreach ($config['mavenBaseUrls'] as $mvnBaseUrl) {
|
|||
if ($found) {
|
||||
$filesize = @stream_copy_to_stream($src, $tempFile);
|
||||
$found = 0 < $filesize;
|
||||
$metaData = @stream_get_meta_data($src);
|
||||
$headers = [];
|
||||
$headerNames = [
|
||||
'Content-Type',
|
||||
'Content-Length',
|
||||
'ETag',
|
||||
'Last-Modified',
|
||||
];
|
||||
|
||||
if (isset($metaData) && array_key_exists('wrapper_data', $metaData)) {
|
||||
foreach ($metaData['wrapper_data'] as $header) {
|
||||
foreach ($headerNames as $headername) {
|
||||
if (stripos($header, $headername) === 0) {
|
||||
$headerValue = trim(substr($header, strlen($headername) + 1)); // +1 to remove the colon
|
||||
$headers[$headername] = $headerValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
trigger_error("Artifact found at $srcUrl", E_USER_NOTICE);
|
||||
|
@ -39,6 +58,21 @@ if (!$found) {
|
|||
trigger_error("Artifact NOT found at any source", E_USER_WARNING);
|
||||
sendHttpReturnCodeAndMessage(404, 'Not found');
|
||||
} else {
|
||||
// Rest temp file pointer
|
||||
fseek($tempFile, 0);
|
||||
|
||||
if (preg_match('/maven-metadata.xml/', $requestedArtifact) || preg_match('/-SNAPSHOT/', $requestedArtifact)) {
|
||||
trigger_error("Found artifact not to cache: ".$requestedArtifact, E_USER_NOTICE);
|
||||
foreach ($headers as $header => $value) {
|
||||
if (is_array($value)) {
|
||||
$value = implode(', ', $value);
|
||||
}
|
||||
header($header.': '.$value);
|
||||
}
|
||||
|
||||
stream_copy_to_stream($tempFile, fopen('php://output', 'w'));
|
||||
} else {
|
||||
trigger_error("Found artifact to cache: ".$requestedArtifact, E_USER_NOTICE);
|
||||
//echo $localFolder."<br>";
|
||||
if (!is_dir($localFolder)) {
|
||||
mkdir($localFolder, 0770, true);
|
||||
|
@ -46,7 +80,7 @@ if (!$found) {
|
|||
$dstPath = $baseLocalFolder.$requestedArtifact;
|
||||
//echo $dstPath;
|
||||
$dst = fopen($dstPath, 'w');
|
||||
fseek($tempFile, 0);
|
||||
|
||||
stream_copy_to_stream($tempFile, $dst);
|
||||
if (is_file($dstPath)) {
|
||||
chmod($dstPath, 0660);
|
||||
|
@ -54,5 +88,6 @@ if (!$found) {
|
|||
} else {
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue