function api_output_utils_start_headers($rsp, $more = array())
{
    $defaults = array('is_error' => 0);
    $more = array_merge($defaults, $more);
    $codes = http_codes();
    $status_code = 200;
    if (isset($more['is_error']) && $more['is_error']) {
        $code = $rsp['error']['code'];
        $status_code = isset($codes[$code]) ? $code : 500;
    } else {
        if (isset($more['created'])) {
            $status_code = 201;
        } else {
        }
    }
    $status = "{$status_code} {$codes[$status_code]}";
    $enc_status = htmlspecialchars($status);
    utf8_headers();
    header("HTTP/1.1 {$enc_status}");
    header("Status: {$enc_status}");
    if (isset($more['is_error'])) {
        header("X-api-error-code: " . htmlspecialchars($rsp['error']['code']));
        header("X-api-error-message: " . htmlspecialchars($rsp['error']['message']));
    }
}
Esempio n. 2
0
function http_codes_send_headers($code)
{
    $codes = http_codes();
    $status = "{$code} {$codes[$code]}";
    header("HTTP/1.1 {$status}");
    header("Status: {$status}");
}
 public function cekToken()
 {
     // Template for getting $data from middleware ApiAccess
     $data = Request::instance()->query('data');
     return Response::json(['status' => 200, 'message' => http_codes(200), 'data' => $data], 200);
 }
Esempio n. 4
0
    header("Status: {$status}");
    if ($retry = intval($GLOBALS['cfg']['site_disabled_retry_after'])) {
        header("Retry-After: {$retry}");
    }
    $smarty->display("page_site_disabled.txt");
    exit;
}
# Unavailable is distinct from disabled in that it's used to account
# for nginx's lack of a decent health check plugin that both checks
# health and removes nodes from its list of upstreams. And to make matters
# worse 501 (Not Implemented) errors are not supported by nginx's
# 'proxy_next_upstream' directive. So we're just going to use 502 and
# carry on... (20130913/straup)
if ($GLOBALS['cfg']['site_unavailable'] && !$this_is_shell) {
    loadlib("http_codes");
    $codes = http_codes();
    $code = 502;
    $status = "{$code} {$codes[$code]}";
    if ($this_is_api) {
        loadlib("api");
        api_config_freakout_and_die($code, "Not implemented");
    }
    header("HTTP/1.1 {$status}");
    header("Status: {$status}");
    $smarty->display("page_site_unavailable.txt");
    exit;
}
#
# Smarty stuff
#
$GLOBALS['error'] = array();