Etag没有出现在Laravel API的标头中

时间:2018-10-08 10:20:42

标签: php laravel api etag

我正在使用Laravel 5.7构建API(已通过Passport认证),并带有一些中间件以在标头中发送ETag。中间件看起来像这样:

public function handle($request, Closure $next)
{
    if (!$request->isMethod('get')) {
        return $next($request);
    }

    $response = $next($request);

    $currentEtag = DB::table('etag')->first()->etag;

    $response->setEtag($currentEtag);

    return $response;
}

但是当我向应用了此中间件的控制器发出GET请求时,响应头中没有ETag键。我知道正在调用中间件(通过在其中插入dd命令)。我的响应标题看起来像这样:

Date: Mon, 08 Oct 2018 10:18:21 GMT
Server: Apache/2.4.25 (Debian)
Cache-Control: private, must-revalidate
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
Vary: Authorization
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Transfer-Encoding: chunked
Content-Type: application/json

编辑:

我也在使用laravel-cors中间件。在配置文件中,我有:

'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedOriginsPatterns' => [],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'],
'exposedHeaders' => ['ETag'],
'maxAge' => 0,

0 个答案:

没有答案