This logic always sets the headersOnly flag to true, even if you pass false. Should you be explicitly checking for undefined here?