Generate a succss response, with HTTP status code $code and body $body

@param  int    $code       2xx series HTTP status code
@param  string $body       Optional body to send
@return self
485373
function success(int $code, string $body=''): \Nofuzz\Http\HTTPResponse
  {
    $this->setStatusCode($code);
    $this->setBody($body);

    return $this;
  }
1190234
public static function _sendHTTPStatusCode($code, $customDescription = FALSE) {
        if (!preg_match('/\d\d\d/', $code)) {
            _Log::warn("Invalid status code: $code - Using default '200 OK' response");
            $code = 200;
        }

        if ($customDescription === FALSE) {
            $description = isset(_WebResponseIncludes::$STATUS_CODES[$code]) ? _WebResponseIncludes::$STATUS_CODES[$code] : '';
        } else {
            $description = $customDescription;
        }
        header("HTTP/1.0 $code $description");
    }
594933
public function getResponse($responseCode)
    {
        return isset($this->responses[$responseCode]) ? $this->responses[$responseCode] : null;
    }
506277
public function getResponse(int $code): Response
    {
        if (!isset($this->responses[$code])) {
            if (isset($this->responses[0])) {
                // Return default response
                return $this->responses[0];
            }
            throw new \InvalidArgumentException(
                "Operation '{$this->getId()}' does not have a definition for status '$code'" .
                " (has " . implode(', ', array_keys($this->responses)) . ')'
            );
        }

        return $this->responses[$code];
    }
84357
public static function isResponseWithoutBody(int $code): bool
    {
        switch ($code) {
            case self::NO_CONTENT:
            case self::NOT_MODIFIED:
                return true;
        }
        
        return ($code >= 100 && $code < 200);
    }
1224436
public function withCode($code)
    {
        $url = Config::get('url.login_with_code');
        $cookie = $this->getCookieOrNew();

        $param['__VIEWSTATE'] = true;
        $param['txtUserName'] = $this->username;
        $param['TextBox2'] = $this->password;
        $param['txtSecretCode'] = $code;
        $param['RadioButtonList1'] = '学生';
        $param['Button1'] = '';

        $response = $this->request('post', [$url, $param, ['cookies' => $cookie]]);
        $body = (string)$response->getBody();
        // Login success
        if (preg_match("/xs_main/", $body)) {
            return $cookie;
        }
        // Get the error
        $content = mb_convert_encoding($body, "utf-8", "gb2312");
        if (preg_match('/alert\((.*?)\)/', $content, $matches)) {
            throw new HttpException(trim($matches[1], '\'"'), 10004);
        }

        throw new HttpException("login failed!", 10003);
    }
28831
public function send($data, $code = 200, array $headers = [])
    {
        if (is_array($data) || $data instanceof \stdClass || is_object($data)) {
            return $this->json($data, $code, $headers);
        }

        $this->code = $code;

        foreach ($headers as $key => $value) {
            $this->addHeader($key, $value);
        }

        $this->content = $data;

        return $this->buildHttpResponse();
    }
67013
public function withCode(int $code): PayloadInterface
    {
        if ($this->code === $code) {
            return $this;
        }

        $clone = clone $this;
        $clone->code = $code;

        return $clone;
    }
428922
public static HttpResponse response(String body) {
        return new HttpResponse().withStatusCode(OK_200.code()).withReasonPhrase(OK_200.reasonPhrase()).withBody(body);
    }
535897
public function code ( $code = NULL ) {
      if ( $code === NULL )
        return $this->code;
      if ( ResponseCode::find( $code ) === NULL )
        throw new \InvalidArgumentException( "Response: no code $code" );
      $this->code = intval( $code );
      return $this;
    }
730218
public function withStatus($code = 200)
    {
        if (!array_key_exists($code, self::$responseCodes)) {
            throw new \Exception('That header code '.$code.' is not allowed.');
        }

        $this->code = $code;
        $this->reasonPhrase = self::$responseCodes[$code];

        return $this;
    }
600634
public function status($code)
    {
        if (in_array((int) $code, array_keys(self::$header), true)) {
            $this->code = $code;

            @header('HTTP/1.1 '. $code .' '. self::$header[$code], $this->override, $code);
        }

        return $this;
    }
754726
public function setHttpCode(int $code): Response
    {
        if ($this->response_finished) {
            return $this;

        }

        $this->response_code = $code;

        return $this;
    }
1030738
function setHttpStatus($code)
    {
        $this->head[0] = $this->http_protocol.' '.self::$HTTP_HEADERS[$code];
        $this->http_status = $code;
    }
162457
public function getBody($code)
	{
	    ob_start();
	    
	    $this->render($code);
	    
	    $content = ob_get_contents();
	    ob_end_clean();
	    
	    return $content;
	}
874892
public function setBody($body)
    {
        $this->code = array(new CodeLineGenerator($body, $this->getIndentationLevel(), $this->getIndentationString()));

        return $this;
    }
1252192
public function setHttpResponseCode($code)
    {
        if (!is_int($code) || (100 > $code) || (599 < $code)) {
            throw new \Exception('Invalid HTTP response code');
        }

        $this->_isRedirect = (300 <= $code) && (307 >= $code);
        $this->_httpResponseCode = $code;
        return $this;
    }