diff --git a/src/Illuminate/Http/Middleware/SetCacheHeaders.php b/src/Illuminate/Http/Middleware/SetCacheHeaders.php new file mode 100644 index 000000000000..d43d8ec2498a --- /dev/null +++ b/src/Illuminate/Http/Middleware/SetCacheHeaders.php @@ -0,0 +1,54 @@ +isMethodCacheable() || ! $response->getContent()) { + return $response; + } + + if (is_string($options)) { + $options = $this->parseOptions($options); + } + + if (isset($options['etag']) && $options['etag'] === true) { + $options['etag'] = md5($response->getContent()); + } + + $response->setCache($options); + $response->isNotModified($request); + + return $response; + } + + /** + * Parse the given header options. + * + * @param string $options + * @return array + */ + protected function parseOptions($options) + { + return collect(explode(';', $options))->mapWithKeys(function ($option) { + $data = explode('=', $option, 2); + + return [$data[0] => $data[1] ?? true]; + })->all(); + } +}