Setup response headers and body by your controller or other logic.
436474
public function prepareResponse(): void
    {
        // change default HTTP status code
        $this->response->setStatusCode(200);

        // clear default response headers
        $this->response->resetHeaders();

        // add your response headers
        $this->response->setCharset('UTF-8');
        $this->response->setContentType('text/html');
        $this->response->addHeader(
            'X-Some-Header-Example-Name: headerValueExample'
        ); // add some other headers by this example

        // call here your controller to get real response body
        $body = 'This is an example generated in Route <i>' . get_class($this) . '</i> with a fictive Controller.';

        // set body to response as response body
        $this->response->setBody($body);
    }
1010043
protected function preProcess(): void
    {
        Router::process();

        // disable Layout for XmlHttpRequests
        if (Request::isXmlHttpRequest()) {
            $this->layoutFlag = false;
        }

        // switch to JSON response based on Accept header
        if (Request::checkAccept([Request::TYPE_HTML, Request::TYPE_JSON]) === Request::TYPE_JSON) {
            $this->layoutFlag = false;
            Response::setType('JSON');
        }
    }
828264
function onHeaders(ev, status, newUrl, oldUrl, statusCode, method, referrer, headers, resourceType) {
    if (resourceType !== 'mainFrame') return;

    let headerArray = [];

    Object.keys(headers).forEach(name => {
      headers[name].forEach(value => {
        headerArray.push({ name, value });
      });
    });

    response = {
      url: newUrl,
      method,
      status: statusCode,
      contentType: headers['content-type'][0],
      headers: headerArray
    };

    notify([ 'header event', status, newUrl, oldUrl, statusCode, method, referrer, headers, resourceType ]);
  }
372751
public function setup()
    {
        if (!$this->_checkRequestType('jsonapi')) {
            return;
        }

        $appClass = Configure::read('App.namespace') . '\Application';

        // If `App\Application` class exists it means Cake 3.3's PSR7 middleware
        // implementation is used and it's too late to register new error handler.
        if (!class_exists($appClass, false)) {
            $this->registerExceptionHandler();
        }
    }
37021
def _add_resposne_headers(self, django_response, devil_response):
        

        try:
            headers = devil_response.headers
        except AttributeError:
            # ok, there was no devil_response
            pass
        else:
            for k, v in headers.items():
                django_response[k] = v
        return django_response
864740
protected function setup() {
		// Clear global hashes.
		$this->urls        = $this->predef_urls;
		$this->titles      = $this->predef_titles;
		$this->html_hashes = array();
		$this->in_anchor   = false;
	}
310788
private function initializeRequest()
    {
        $this->responseBody = '';
        $this->responseHeaders = array();
        $this->lastError = false;
        $this->addHeader('Accept', $this->getContentType());

        curl_setopt($this->curl, CURLOPT_POST, false);
        curl_setopt($this->curl, CURLOPT_PUT, false);
        curl_setopt($this->curl, CURLOPT_HTTPGET, false);

        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->headers);
    }
796214
function Head($uri) {
      $this->responseHeaders = $this->responseBody = '';

      $uri = $this->makeUri($uri);

      if ($this->sendCommand('HEAD ' . $uri . ' HTTP/' . $this->protocolVersion)) {
        $this->processReply();
      }

      return $this->reply;
    }
523747
protected function prepareHeaders()
    {
        if (!isset($this->headers['Content-Length'])) {

            $content_length = strlen($this->data);

            if ($content_length > 0 || $this->method === 'POST' || $this->method === 'PUT') {
                $this->headers['Content-Length'] = $content_length;
            }
        }

        if (isset($this->uri['user']) && !isset($this->headers['Authorization'])) {
            $pass = isset($this->uri['pass']) ? ':' . $this->uri['pass'] : ':';
            $this->headers['Authorization'] = 'Basic ' . base64_encode($this->uri['user'] . $pass);
        }
    }
587611
private function populateResponseHeaders()
	{
		$done = FALSE;
		$line = NULL;
		$header = '';
		$buffer = NULL;

		// When using a file stream.
		if ( $this->resourceType === static::RESOURCE_TYPE_FILE ) {
			$done = \feof( $this->resource );
		}

		// Read the headers from the resource.
		while ( !$done )
		{
			$buffer = $this->readFromResource( 1 );
			// Update stream
			$this->content .= $buffer;
			$header = \strstr( $this->content, "\r\n\r\n", TRUE );
			// When you reach the end of the header, then exit the loop.
			if ( $buffer === '' || $header !== FALSE )
			{
				break;
			}
		}

		// Update cursor position.
		$this->position += \strlen( $this->content );
		// Parse header.
		if ( strlen(trim($header)) > 0 )
		{
			// Set header
			$this->wrapperData = explode( "\r\n", $header );
		}
	}
1311911
private function init_response_properties() {
		// Initialze some properties
		$this->response->status = null;
		$this->response->possible_methods = null;
		$this->response->message = null;
		$this->response->more_info = null;
		$this->response->data = null;
		$this->response->paging = null;
	}
1201611
function handleResponse(ctx, response) {
  ctx.body = response.body;
  ctx.status = response.status;
  ctx.set(response.headers);
}
608642
function createResponse(xhr, request){
  
  // XHR header processing borrowed from jQuery
  var responseHeaders = {}, match;
  while ((match = headersRegex.exec(xhr.getAllResponseHeaders()))) {
		responseHeaders[match[1].toLowerCase()] = match[2];
	}
	
  return {
    statusCode: xhr.status,
    statusText: xhr.statusText,
    headers: responseHeaders,
    originalUrl: request.url,
    effectiveUrl: request.url,
    redirected: false,
    requestMethod: request.method,
    requestHeaders: request.headers,
    body: xhr.responseText,
    retries: 0,
    throttled: false
  };
}
1165544
def make_response(status, headers, payload, environ):
    
    return Response(body=payload, status=int(status.split()[0]),
                    headers=headers)
434225
def setup(self):
        
        [c.start() for c in self.controllers]
        [c.wait_to_start() for c in self.controllers]
612470
protected function _buildAndExecuteProxyResponse()
    {
        if($this->_responseModifier)
        {
          $data = call_user_func_array($this->_responseModifier, array(&$this->_responseBody, &$this->_responseHeaders));
        }

        $this->_generateProxyResponseHeaders();

        $this->_output($this->_responseBody);
    }
105947
private void setResponse(int statusCode, String statusMessage, String responseBody, Map<String, List<String>> responseHeaders)
    {
        mStatusCode      = statusCode;
        mStatusMessage   = statusMessage;
        mResponseBody    = responseBody;
        mResponseHeaders = responseHeaders;
    }