Inject some code just before any tag.

@param ResponseInterface $response
@param string            $code
@param string            $tag

@return ResponseInterface
192571
private function inject(ResponseInterface $response, $code, $tag = 'body')
    {
        $html = (string) $response->getBody();
        $pos = strripos($html, "</{$tag}>");

        if ($pos === false) {
            $response->getBody()->write($code);

            return $response;
        }

        $body = self::createStream();
        $body->write(substr($html, 0, $pos).$code.substr($html, $pos));

        return $response->withBody($body);
    }
1052718
private function sendResponse($code, $message, $response = null) {
        $ret = [
            'code' => $code,
            'message' => $message,
        ];
        if ($response) {
            $ret['response'] = $response;
        }
        return $ret;
    }
875127
public function destroy(TagRequest $request, Tag $tag)
    {
        try {

            $tag->delete();
            return $this->response->message(trans('messages.success.deleted', ['Module' => trans('blog::tag.name')]))
                ->code(202)
                ->status('success')
                ->url(guard_url('blog/tag/0'))
                ->redirect();

        } catch (Exception $e) {

            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('blog/tag/' . $tag->getRouteKey()))
                ->redirect();
        }

    }
446061
protected function respond($response, $code)
    {
        if (isset($response[0])) {
            foreach ($response as $responseItem) {
                $responses[] = $this->respond($responseItem, $code);
            }

            return $responses;
        }

        return $this->mapResponse($this->isSuccess($response, $code), $response);
    }
631523
public function inject(Response &$response)
    {
        $renderer = $this->debugBar->getJavascriptRenderer('/__debug__/');

        if (stripos($response->headers->get('Content-Type'), 'text/html') === 0) {
            $content = $response->getContent();
            $content = self::injectHtml($content, $renderer->renderHead(), '</head>');
            $content = self::injectHtml($content, $renderer->render(), '</body>');
            $response->setContent($content);
        }
    }
881507
public static function addTags($line,$tag) {
		$lineFinal = "<".$tag.">".preg_replace("/<[A-z0-9-_]{1,}>[^<]{1,}<\/[A-z0-9-_]{1,}>/","</".$tag.">$0<".$tag.">",$line)."</".$tag.">";
		return $lineFinal;
	}
242439
public function handleRequest(GetResponseEvent $event)
    {
        if (!($tagcacheConfig = $this->getTagcacheConfig($event->getRequest()))) {
            return;
        }

        if (is_array($cacheContent = $this->tagcache->get($tagcacheConfig->getKey()))) {
            if ($cacheContent['Expires'] - (time() - $cacheContent['CreatedAt']) < 0) {
                return;
            }
            $response = new TagcacheResponse($this->renderCacheContent($cacheContent));
            $response->headers->add($cacheContent['Headers']);
            $event->setResponse($response);
        }
    }
119962
public function tagAssign($tag, $content)
    {
        $name = $this->autoBuildVar($tag['name']);
        $flag = substr($tag['value'], 0, 1);

        if ('$' == $flag || ':' == $flag) {
            $value = $this->autoBuildVar($tag['value']);
        } else {
            $value = '\'' . $tag['value'] . '\'';
        }

        $parseStr = '<?php ' . $name . ' = ' . $value . '; ?>';

        return $parseStr;
    }
854194
public function recv($statement, array $parameters = array(), $tag = null)
    {
        $runResponse = new Response();
        $r = $this->unpacker->unpack();
        $shouldThrow = false;
        if ($r->isFailure()) {
            try {
                $runResponse->onFailure($r);
            } catch (MessageFailureException $e) {
                // server ignores the PULL ALL
                $this->handleIgnore();
                $this->handleIgnore();
                $this->sendMessage(new AckFailureMessage());
                $this->handleIgnore();
                // server success for ACK FAILURE
                $r2 = $this->handleSuccess();
                $shouldThrow = $e;
            }
        }

        if ($shouldThrow !== false) {
            throw $shouldThrow;
        }

        if ($r->isSuccess()) {
            $runResponse->onSuccess($r);
        }

        $pullResponse = new Response();

        while (!$pullResponse->isCompleted()) {
            $r = $this->unpacker->unpack();

            if ($r->isRecord()) {
                $pullResponse->onRecord($r);
            }

            if ($r->isSuccess()) {
                $pullResponse->onSuccess($r);
            }
        }

        $cypherResult = new CypherResult(Statement::create($statement, $parameters, $tag));
        $cypherResult->setFields($runResponse->getMetadata()[0]->getElements());

        foreach ($pullResponse->getRecords() as $record) {
            $cypherResult->pushRecord($record);
        }

        if (null !== $pullResponse && array_key_exists(0, $pullResponse->getMetadata())) {
            $metadata = $pullResponse->getMetadata()[0]->getElements();
            $stats = array_key_exists('stats', $metadata) ? $metadata['stats'] : array();
            $cypherResult->setStatistics($stats);
        }

        return $cypherResult;
    }
119213
protected function createRedirectResponse($url, $code = 301)
    {
        $response = $this->getComponentResponseFactory()
            ->createComponentResponse();

        $response->setCode($code)
                 ->getHeaders()
                    ->setHeader('Location', $url);

        return $response;
    }
150374
protected function parseResponse($response)
    {
        synapse()->tags->each(function ($tag) use (&$response) {
            $class = "\\Axiom\\Rivescript\\Cortex\\Tags\\$tag";
            $tagClass = new $class();

            $response = $tagClass->parse($response, $this->input);
        });

        return $response;
    }
1057403
private function injectLiveReload(Response $response)
    {
        $content = $response->getContent();
        $content = str_replace('</body>', '
            <script>
                document.write(\'<script src="http://\' + (location.host || \'localhost\').split(\':\')[0] + \':35729/livereload.js?snipver=1"></\' + \'script>\')
            </script></body>', $content);
        $response->setContent($content);
    }
1093908
public function createResponse(array $responseData, $code = 200)
    {
        $responseType = '.json';
        
        $route = Request::route();
        
        $responseType = $route ? $route->parameter('type', $responseType) : $responseType;

        switch ($responseType) {
            case '.yaml':
                return $this->yamlResponse($responseData, $code);
            case '.xml':
                return $this->xmlResponse($responseData, $code);
            default:
                return $this->jsonResponse($responseData, $code);
        }
    }
39960
private function withText(ResponseInterface $response, $text)
    {
        if (is_array($text)) {
            $text = implode(PHP_EOL, $text);
        }

        return $this
            ->withNewBody($response, $text)
            ->withHeader('Content-Type', 'text/plain');
    }
613697
protected function addCookieConsentScriptToResponse(Response $response)
    {
        $content = $response->getContent();

        $closingBodyTagPosition = $this->getLastClosingBodyTagPosition($content);

        $content = ''
            .substr($content, 0, $closingBodyTagPosition)
            .view('cookieConsent::index')->render()
            .substr($content, $closingBodyTagPosition);

        return $response->setContent($content);
    }
482911
public void sendResponse(int code, String response) {
        if(con.isClosed()) return;

        if(response == null || response.isEmpty()) {
            response = "Unknown";
        }

        try {
            if(response.charAt(0) == '-') {
                writer.write(code + response + "\r\n");
            } else {
                writer.write(code + " " + response + "\r\n");
            }
            writer.flush();
        } catch(IOException ex) {
            Utils.closeQuietly(this);
        }
        responseSent = true;
    }
1364045
protected function replaceMarkerWithContent($node, $tag)
    {
        $content = $this->getShortcodeReplacementText($tag);

        if ($content) {
            /** @var HTMLValue $parsed */
            $parsed = HTMLValue::create($content);
            $body = $parsed->getBody();
            if ($body) {
                $this->insertListAfter($body->childNodes, $node);
            }
        }

        $this->removeNode($node);
    }