custom block menu path returns json Ok, but a 404 status header I created a custom path via hook_menu with a page callback to a function that prints json.

It all works in the sense that requesting: http://cms.tripchi.com/tripchi/getme returns my JSON, but the header says it's 404 which is throwing off everything in the app. This only returns the 404 status on the client's godaddy server (PHP Version 5.4.19 w/ CGI/FastCGI), but returns 200/Ok on my local PHP Version 5.3.5 w/ Apache 2.0 Handler. All Drupal configurations and databases are equal.

hook_menu

function tripchi_menu() {
    return array(
        'tripchi/getme' =&gt; array(
            'title' =&gt; 'My Profile',
            'description' =&gt; 'mobile test for user status and object',
            'access callback' =&gt; 'user_access',
            'access arguments' =&gt; array('access content'),
            'page callback' =&gt; 'tripchi_getme')
    );
}


callback function

function tripchi_getme(){
    $user = $GLOBALS['user'];
    $json = array();
    // ... a bunch of stuff to construct a special array;
    drupal_add_http_header('Status', 'Ok');
    drupal_add_http_header('Access-Control-Allow-Origin', '*');
    http_response_code(200);
    //echo json_encode($json);
    drupal_json_output($json);
    drupal_exit();
    //die();
    // i've tried all combinations of commenting/uncomming the above...
}


below screenshot of the requests locally (right) and remotely (left):


why does this always return 404 but also give me my perfectly json encoded data?
First of all, for JSON output use drupal_json_output as a delivery callback in your menu. It will make thinks much easier:

function tripchi_menu() {
    return array(
        'tripchi/getme' =&gt; array(
            'title' =&gt; 'My Profile',
            'description' =&gt; 'mobile test for user status and object',
            'access callback' =&gt; 'user_access',
            'access arguments' =&gt; array('access content'),
            'page callback' =&gt; 'tripchi_getme',
            'delivery callback' =&gt; 'drupal_json_output'
         ),
    );
}


Then in your menu callback just return array. You don't need any other fancy stuff. I also faced 404 issue, but with this solution AND explicitly set response code 200 everything worked fine.

function tripchi_getme(){
    global $user;
    $json = array();
    // ... a bunch of stuff to construct a special array;

    // Only this was needed to make the stuff work.
    http_response_code(200);

    return $json;
}


I couldn't tell if the cause of my trouble was drupal or apache or both, but this certainly helped. Note that Access-Control-Allow-Origin was not needed to make this work (and I didn't plan to use cross domain calls either).