aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework/Http/TextPlainResponse.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/AppFramework/Http/TextPlainResponse.php')
-rw-r--r--lib/public/AppFramework/Http/TextPlainResponse.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/public/AppFramework/Http/TextPlainResponse.php b/lib/public/AppFramework/Http/TextPlainResponse.php
new file mode 100644
index 00000000000..9dfa2c5544d
--- /dev/null
+++ b/lib/public/AppFramework/Http/TextPlainResponse.php
@@ -0,0 +1,47 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * A renderer for text responses
+ * @since 22.0.0
+ * @template S of Http::STATUS_*
+ * @template H of array<string, mixed>
+ * @template-extends Response<Http::STATUS_*, array<string, mixed>>
+ */
+class TextPlainResponse extends Response {
+ /** @var string */
+ private $text = '';
+
+ /**
+ * constructor of TextPlainResponse
+ * @param string $text The text body
+ * @param S $statusCode the Http status code, defaults to 200
+ * @param H $headers
+ * @since 22.0.0
+ */
+ public function __construct(string $text = '', int $statusCode = Http::STATUS_OK, array $headers = []) {
+ parent::__construct($statusCode, $headers);
+
+ $this->text = $text;
+ $this->addHeader('Content-Type', 'text/plain');
+ }
+
+
+ /**
+ * Returns the text
+ * @return string
+ * @since 22.0.0
+ * @throws \Exception If data could not get encoded
+ */
+ public function render() : string {
+ return $this->text;
+ }
+}