Mongrel2\Tool::http_response PHP Метод

http_response() публичный статический Метод

public static http_response ( $body, $code, $status, $headers )
    public static function http_response($body, $code, $status, $headers)
    {
        $http = "HTTP/1.1 %s %s\r\n%s\r\n%s";
        if (is_null($headers)) {
            $headers = array();
        }
        $headers['Content-Length'] = strlen($body);
        $hd = "";
        foreach ($headers as $k => $v) {
            $hd .= sprintf("%s: %s\r\n", $k, $v);
        }
        return sprintf($http, $code, $status, $hd, $body);
    }

Usage Example

Пример #1
0
 public function testHttpResponse()
 {
     $fix = "HTTP/1.1 200 OK\r\nX-foo: Yo\r\nContent-Length: 3\r\n\r\nfoo";
     $ret = Tool::http_response("foo", 200, "OK", array('X-foo' => 'Yo'));
     $this->assertEquals($ret, $fix);
 }