@param string $str
@param string $contentType

@return ResponseInterface
763919
public function print(
        string $str,
        string $contentType = null
    ): ResponseInterface
    {
        $body = Factory::streamFromFile('php://temp', 'wb+');
        $body->write($str);
        $body->rewind();

        if ($contentType) {
            $this->header->set('Content-Type', $contentType);
        }

        return $this->setStatus(200)->response($body);
    }
432428
public function decode($content, $contentType)
    {
        $converter = $this->getConverter($contentType);

        return $converter->decode($content);
    }
768494
public static function createNotParsable(string $contentType, string $error = null): self
    {
        $message = sprintf('Data is not parsable with content-type: "%s"', $contentType);
        if (null !== $error) {
            $message .= sprintf(', error: "%s"', $error);
        }

        return new self($message);
    }
134911
public function setContentType(string $contentType, string $charset = null)
    {
        $this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));

        return $this;
    }
253907
public function appendPageContent(string $str): PdfInterface
    {
        $this->setProperty('pageContent', $str);
        $this->mpdf->WriteHTML($this->pageContent);

        return $this;
    }
532281
public function download($fileName, $contentType, $contents)
    {
        $body = $this->builder->messages()->stringStream($contents);
        return $this->downloadResponse($fileName, $contentType, $body);
    }
90473
public function setContentType($contentType)
    {
        $this->contentType = $contentType;

        $this->setHeader('Content-Type', $contentType . '; charset=' . $this->getCharset());

        return $this;
    }
419046
public function post($url, $data, $contentType = 'application/json')
    {
        $uri = $this->buildUrl($url);

        $request = $this->requestFactory->createRequest('POST', $uri);
        if (!is_null($contentType)) {
            $request = $request->withHeader('Content-Type', $contentType);
            $request = $request->withHeader('Accept', $contentType);
        }
        $request = $request->withBody(stream_for($data));

        $response = $this->request($request);

        return strval($response->getBody());
    }
471190
protected function createResponse($content, $contentType)
    {
        $resp = new HttpResponse();

        $resp->setStatusCode(200)
             ->setContent($content);
        $resp->getHeaders()->addHeaders(array(
            'Content-Length'    => strlen($content),
            'Content-Type'      => $contentType
        ));
        return $resp;
    }
138563
private function processXmlResponse($url, $payload = '', $contentType = 'application/xml')
    {
        if (extension_loaded('curl')) {
            $ch = curl_init();
            if (!$ch) {
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
            }
            $timeout = 10;

            // Needed to store the JSESSIONID
            $cookiefile     = tmpfile();
            $cookiefilepath = stream_get_meta_data($cookiefile)['uri'];

            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefilepath);
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefilepath);
            if (!empty($payload)) {
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
                curl_setopt($ch, CURLOPT_HTTPHEADER, [
                    'Content-type: ' . $contentType,
                    'Content-length: ' . mb_strlen($payload),
                ]);
            }
            $data = curl_exec($ch);
            if ($data === false) {
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
            }
            curl_close($ch);

            $cookies = file_get_contents($cookiefilepath);
            if (strpos($cookies, 'JSESSIONID') !== false) {
                preg_match('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/', $cookies, $output_array);
                $this->setJSessionId($output_array['JSESSIONID']);
            }

            return new SimpleXMLElement($data);
        } else {
            throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.');
        }
    }
136686
public function convertResponseBodyToObject($responseBody, $contentTypeHeader)
    {
        try {
            $this->responseObject = $this->getKernel()->getContainer()->get('ezpublish_rest.input.dispatcher')->parse(
                new Message(
                    array('Content-Type' => $contentTypeHeader),
                    $responseBody
                )
            );
        } catch (\Exception $e) {
            // when errors/exceptions popup on form the response we need also to
            // test/verify them
            $this->responseObject = $e;
        }

        return $this->responseObject;
    }
874631
static public function parse($str, $content_type)
    {
        switch ($content_type) {
            case 'json':
                return self::toJson($str);
            
            case 'xml':
                return self::toXml($str);

            default:
                return $str;
        }
    }
982294
public function setBody($body, string $contentType = null, string $contentCharset = null): self
    {
        if ($body != null) {
            if ($body instanceof ReturnResponse) {
                $this->setStatus($body->getStatusCode())
                     ->setHeaders($body->getHeaders())
                     ->setCookies($body->getCookies());

                $body = new Body(
                    $body->getContent(),
                    $body->getContentType() ?? $this->body->getContentType(),
                    $body->getContentCharset() ?? $this->body->getContentCharset()
                );

                // override, no need to all stuff below
                if ($body->isImage()) {
                    $this->body = $body;

                    return $this;
                }
            }

            // no elseif, could be a Body already
            if ($body instanceof Body) {
                $body = $this->body
                    ->setContent($body->getContent())
                    ->setContentType($body->getContentType())
                    ->setContentCharset($body->getContentCharset())
                    ->getContent();
            }
        }

        if ($body !== null) {
            // json stuff (array/object returns could be encoded if content type is json)
            $bodyType = gettype($body);
            if ($bodyType != 'string') {
                switch ($bodyType) {
                    case 'array': case 'object':
                        $jsonOptions = $this->app->configValue('response.json');
                        if ($jsonOptions != null // could be emptied by developer to disable json
                            && ($bodyContentType = $this->body->getContentType())
                            && (strpos($bodyContentType, '/json') || strpos($bodyContentType, '+json'))
                        ) {
                            [$body, $error] = Encoder::jsonEncode($body, $jsonOptions);
                            if ($error) {
                                throw new EncoderException($error);
                            }
                        }
                        break;
                    case 'integer': case 'double':
                        $body = (string) $body;
                        break;
                }
            }

            // not encoded/converted
            if (!is_string($body)) {
                throw new HttpException("Body content must be string, number, array or object".
                    " (or encoded in invoked service method if froq\\http\\response\\JsonResponse".
                    " not used, or content type set as application/json or text/json),".
                    " '{$bodyType}' given");
            }

            // gzip stuff
            $bodyLength = strlen($body);
            if ($bodyLength > 0) { // prevent gzip corruption for 0 byte data
                $gzipOptions = $this->app->configValue('response.gzip');
                $acceptEncoding = (string) $this->app->request()->getHeader('Accept-Encoding');

                $canGzip = $gzipOptions != null // could be emptied by developer to disable gzip
                    && strpos($acceptEncoding, 'gzip') !== false
                    && $bodyLength >= ($gzipOptions['minlen'] ?? 1);

                if ($canGzip) {
                    [$body, $error] = Encoder::gzipEncode($body, $gzipOptions);
                    if ($error) {
                        throw new EncoderException($error);
                    }

                    // cancel php's compression & add required headers
                    if (!headers_sent()) {
                        ini_set('zlib.output_compression', 'Off');
                    }
                    $this->setHeader('Content-Encoding', 'gzip');
                    $this->setHeader('Vary', 'Accept-Encoding');
                }
            }

            // finally..
            $this->body->setContent($body)
                       ->setContentLength(strlen($body));
        }

        // '' accepted for 'none' responses
        if ($contentType !== null) {
            $this->body->setContentType($contentType);
        }
        if ($contentCharset !== null) {
            $this->body->setContentCharset($contentCharset);
        }

        return $this;
    }
113855
public function downloadFile($fileName, $contentType, $file)
    {
        $body = $this->builder->messages()->stream($file);
        return $this->downloadResponse($fileName, $contentType, $body);
    }
1276385
public static Action contentType(final String contentType) {
        return new Action(r -> {
            r.setContentType(contentType);
            return r;
        });
    }
1309223
public function startCreatingContent(string $contentType): ContentUpdateItemPage
    {
        $this->rightMenu->clickButton('Create');

        $contentTypePicker = ElementFactory::createElement($this->context, ContentTypePicker::ELEMENT_NAME);
        $contentTypePicker->select($contentType);

        $contentUpdatePage = PageObjectFactory::createPage($this->context, ContentUpdateItemPage::PAGE_NAME, $contentType);
        $contentUpdatePage->verifyIsLoaded();

        return $contentUpdatePage;
    }
1359564
final private function convertResponseBodyToObject($body, $content_type)
	{
		/* No body to convert */
		if (empty($body)) {
			return null;
		}

		/*  Convert to Mollie_Response object or return as string. */
		if (preg_match('/(application|text)\/xml/i', $content_type)) {
			return simplexml_load_string($body, "Mollie_Response");
		}
		return $body;
	}