diff --git a/.htaccess b/.htaccess
index 894b08a..a6e423d 100644
--- a/.htaccess
+++ b/.htaccess
@@ -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]
diff --git a/src/mvncache.php b/src/mvncache.php
index a3cfa7c..6b8ebd4 100644
--- a/src/mvncache.php
+++ b/src/mvncache.php
@@ -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,20 +58,36 @@ if (!$found) {
trigger_error("Artifact NOT found at any source", E_USER_WARNING);
sendHttpReturnCodeAndMessage(404, 'Not found');
} else {
- //echo $localFolder."
";
- if (!is_dir($localFolder)) {
- mkdir($localFolder, 0770, true);
- }
- $dstPath = $baseLocalFolder.$requestedArtifact;
- //echo $dstPath;
- $dst = fopen($dstPath, 'w');
+ // Rest temp file pointer
fseek($tempFile, 0);
- stream_copy_to_stream($tempFile, $dst);
- if (is_file($dstPath)) {
- chmod($dstPath, 0660);
- header('Location: '.getServerProtocol().'://'.getRequestHostname().$_SERVER["REQUEST_URI"]);
+
+ 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 {
- header('HTTP/1.0 404 Not Found');
+ trigger_error("Found artifact to cache: ".$requestedArtifact, E_USER_NOTICE);
+ //echo $localFolder."
";
+ if (!is_dir($localFolder)) {
+ mkdir($localFolder, 0770, true);
+ }
+ $dstPath = $baseLocalFolder.$requestedArtifact;
+ //echo $dstPath;
+ $dst = fopen($dstPath, 'w');
+
+ stream_copy_to_stream($tempFile, $dst);
+ if (is_file($dstPath)) {
+ chmod($dstPath, 0660);
+ header('Location: '.getServerProtocol().'://'.getRequestHostname().$_SERVER["REQUEST_URI"]);
+ } else {
+ header('HTTP/1.0 404 Not Found');
+ }
}
}
?>