diff --git a/src/Controller/GenerateWebPageController.php b/src/Controller/GenerateWebPageController.php index 8f0c598..cbdea1b 100644 --- a/src/Controller/GenerateWebPageController.php +++ b/src/Controller/GenerateWebPageController.php @@ -51,11 +51,13 @@ class GenerateWebPageController extends ControllerBase { public function generatePage(CollectContainerInterface $collect_container) { $data = json_decode($collect_container->getData(), TRUE); $content = $data['body']; - $accept_header = 'text/html'; - if (preg_match('/application\\/json/', $data['response-headers']['Content-Type'][0])) { - $accept_header = 'application/json'; + if (!is_string($content)) { $content = json_encode($content); } + $accept_header = 'text/html'; + if (!empty($data['response-headers']['Content-Type'])) { + $accept_header = $data['response-headers']['Content-Type'][0]; + } return new Response($content, 200, ['Content-Type' => $accept_header]); } diff --git a/src/Plugin/collect/Schema/FetchUrlSchema.php b/src/Plugin/collect/Schema/FetchUrlSchema.php index 1a994b8..0bd48b2 100644 --- a/src/Plugin/collect/Schema/FetchUrlSchema.php +++ b/src/Plugin/collect/Schema/FetchUrlSchema.php @@ -47,7 +47,7 @@ class FetchUrlSchema extends SchemaBase { return; } $output = array(); - $output['request'] = array( + $output['request-headers'] = array( '#type' => 'table', '#header' => [$this->t('Request headers'), NULL], '#empty' => $this->t('There are no data.'), @@ -56,13 +56,13 @@ class FetchUrlSchema extends SchemaBase { ); foreach ($data['request-headers'] as $key => $value) { - $output['request'][$key] = array( + $output['request-headers'][$key] = array( ['#markup' => $key], ['#markup' => $value[0]], ); } - $output['response'] = array( + $output['response-headers'] = array( '#type' => 'table', '#header' => [$this->t('Response headers'), NULL], '#empty' => $this->t('There are no data.'), @@ -71,7 +71,7 @@ class FetchUrlSchema extends SchemaBase { ); foreach ($data['response-headers'] as $key => $value) { - $output['response'][$key] = array( + $output['response-headers'][$key] = array( ['#markup' => $key], ['#markup' => $value[0]], ); diff --git a/src/Tests/CollectWebTest.php b/src/Tests/CollectWebTest.php index bb97df4..5ea6cf5 100644 --- a/src/Tests/CollectWebTest.php +++ b/src/Tests/CollectWebTest.php @@ -138,15 +138,16 @@ class CollectWebTest extends WebTestBase { 'container_revision' => TRUE, ), t('Save')); $this->assertText(t('Schema config Collect Fetch URL has been saved.')); - $this->assertText(t('Show content in a new window')); - // Test body content and empty Accept header. + // Assert empty Accept header. + // Assert that body content on the generated web page is equal to the body + // content stored in collect container. + $this->clickLink(t('Show content in a new window')); $first_url_container_id = $this->getLatestId(); $data = json_decode(Container::load($first_url_container_id)->getData(), TRUE); $this->assertEqual($data['request-headers']['Accept'][0], ''); $body = $data['body']; - $this->setRawContent($body); - $this->assertRaw('
Test paragraph.
'); + $this->assertEqual($body, $this->getRawContent()); // Test Fetch URL form to page that does not exist. $this->captureWebPage(404);