mirror of
https://github.com/Babibubebon/lodfe.git
synced 2024-09-22 17:34:19 +09:00
fix incorrct content-type header
This commit is contained in:
parent
00325bc094
commit
447d0168b3
2 changed files with 20 additions and 6 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Middleware\ContentNegotiatorMiddleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ResourceController extends Controller
|
||||
|
@ -64,6 +65,8 @@ class ResourceController extends Controller
|
|||
} catch (\EasyRdf_Exception $e) {
|
||||
abort(400);
|
||||
}
|
||||
return $data;
|
||||
$type = ContentNegotiatorMiddleware::mimetypeFromExtension($ext);
|
||||
return response($data)
|
||||
->header('Content-Type', $type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,23 +9,34 @@ class ContentNegotiatorMiddleware
|
|||
{
|
||||
public $defaultType = 'text/html';
|
||||
|
||||
public $acceptableTypes = [
|
||||
public static $acceptableTypes = [
|
||||
'text/html' => 'html',
|
||||
'application/xhtml+xml' => 'html',
|
||||
'text/n3' => 'data',
|
||||
'text/turtle' => 'data',
|
||||
'application/n-triples' => 'data',
|
||||
'application/rdf+xml' => 'data',
|
||||
'application/json' => 'data',
|
||||
'application/ld+json' => 'data',
|
||||
];
|
||||
|
||||
public $fileExtensions = [
|
||||
public static $fileExtensions = [
|
||||
'text/html' => '.html',
|
||||
'application/xhtml+xml' => '.html',
|
||||
'text/turtle' => '.ttl',
|
||||
'application/n-triples' => '.nt',
|
||||
'application/rdf+xml' => '.rdf',
|
||||
'application/json' => '.json',
|
||||
'application/ld+json' => '.jsonld',
|
||||
];
|
||||
|
||||
public static function mimetypeFromExtension($ext)
|
||||
{
|
||||
$extensionToMimetype = array_flip(self::$fileExtensions);
|
||||
return array_key_exists($ext, $extensionToMimetype)
|
||||
? $extensionToMimetype[$ext] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
|
@ -53,15 +64,15 @@ class ContentNegotiatorMiddleware
|
|||
$id = $request->route('id');
|
||||
$negotiatedType = $this->defaultType;
|
||||
foreach ($accepts as $mime => $q) {
|
||||
if (array_key_exists($mime, $this->acceptableTypes)) {
|
||||
if (array_key_exists($mime, self::$acceptableTypes)) {
|
||||
$negotiatedType = $mime;
|
||||
}
|
||||
}
|
||||
|
||||
$redirectTo = $this->acceptableTypes[$negotiatedType] . '.' . $datasetName;
|
||||
$redirectTo = self::$acceptableTypes[$negotiatedType] . '.' . $datasetName;
|
||||
$params = ['id' => $id];
|
||||
if (substr($redirectTo, 0, 4) === 'data') {
|
||||
$params['ext'] = $this->fileExtensions[$negotiatedType];
|
||||
$params['ext'] = self::$fileExtensions[$negotiatedType];
|
||||
}
|
||||
return redirect()->route($redirectTo, $params, 303);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue