예제 #1
0
/**
 * Sends a MHTTPResponse object to the client
 *
 * This funciton is used to send a HTTP response back to the client,
 * the response is represented by an instance of the MHTTPResponse
 * class
 *
 * @see MHTTPResponse
 *
 * @param MHTTPResponse $response The HTTP response to send back to the client
 *
 * @return void
 */
function MSendResponse(MHTTPResponse $response)
{
    $body = $response->body();
    header(sprintf("HTTP/1.1 %d %s", $response->code(), $response->responseString()));
    if ($response->headers()->count() > 0) {
        foreach ($response->headers()->allKeys()->toArray() as $header) {
            header(sprintf("%s: %s", $header, $response->headers()->objectForKey($header)));
        }
    }
    if ($body) {
        echo $body;
    }
}