Skip to content

Commit

Permalink
enforced mimetype
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Aug 19, 2019
1 parent 86e6f3c commit 0ffbeb8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
8 changes: 5 additions & 3 deletions classes/Feed.php
Expand Up @@ -140,12 +140,14 @@ public function response(): \Kirby\Http\Response
$mime = \Kirby\Toolkit\A::get($this->options, 'mime');
$snippet = \Kirby\Toolkit\A::get($this->options, 'snippet');

if ($mime && in_array($mime, array_values(\Kirby\Toolkit\Mime::types()))) {
$allMimeTypes = \Kirby\Toolkit\Mime::types();
$mime = array_search($mime, $allMimeTypes);
if ($mime !== false) {
return new \Kirby\Http\Response($this->string, $mime);
} elseif ($snippet === 'feed/json' || \Bnomei\Feed::isJson($this->string)) {
return new \Kirby\Http\Response($this->string, 'application/json');
return new \Kirby\Http\Response($this->string, 'json');
} elseif ($snippet === 'feed/rss' || \Bnomei\Feed::isXml($this->string)) {
return new \Kirby\Http\Response($this->string, 'application/rss+xml');
return new \Kirby\Http\Response($this->string, 'rss');
}
return new \Kirby\Http\Response('Error: Feed Response', null, 500);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-feed",
"type": "kirby-plugin",
"version": "1.3.0",
"version": "1.3.1",
"description": "Generate a RSS/JSON-Feed from a Pages-Collection",
"license": "MIT",
"authors": [
Expand Down
4 changes: 3 additions & 1 deletion index.php
Expand Up @@ -14,7 +14,9 @@
],
'pagesMethods' => [ // PAGES not PAGE
'feed' => function ($options = [], $force = null) {
return \Bnomei\Feed::feed($this, $options, $force);
$response = \Bnomei\Feed::feed($this, $options, $force);
kirby()->response()->type($response->type());
return $response;
},
],
]);
4 changes: 2 additions & 2 deletions tests/FeedTest.php
Expand Up @@ -97,7 +97,7 @@ public function testForcedMime()
[
'feedurl' => '/feed-yaml',
'snippet' => 'feed/yaml',
'mime' => 'text/plain', // TODO: application/yaml is missing in kirby
'mime' => 'text/html',
]
);
$yamlString = $feed->stringFromSnippet(true)->getString();
Expand All @@ -108,7 +108,7 @@ public function testForcedMime()
$this->assertCount(11, $yaml['items']);

$response = $feed->response();
$this->assertTrue($response->type() === 'text/plain');
$this->assertTrue($response->type() === 'text/html');
}

public function testInvalidOptions()
Expand Down
3 changes: 0 additions & 3 deletions tests/IndexTest.php
Expand Up @@ -36,8 +36,5 @@ public function testFindsFeedRouteYAML()
$response = kirby()->render('/feed-yaml');
$this->assertIsInt($response->code(), 200);
$this->assertTrue('text/html' === $response->type());

// TODO: kirby render sends text/html and not type set by plugin
$this->assertFalse('text/plain' === $response->type());
}
}

0 comments on commit 0ffbeb8

Please sign in to comment.