Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJAX X-Requested-With header is not propagated #2

Open
giles-v opened this issue Apr 21, 2010 · 0 comments
Open

AJAX X-Requested-With header is not propagated #2

giles-v opened this issue Apr 21, 2010 · 0 comments

Comments

@giles-v
Copy link

giles-v commented Apr 21, 2010

Steps to reproduce:

  • Create a PHP script which echoes the contents of $_SERVER['HTTP_X_REQUESTED_WITH']
  • Request it directly in AJAX (e.g. using jQuery, doing $(".output").load("test.php") or similar)
  • Request it via the proxy in AJAX, e.g. $(".output").load("proxy.php?mode=native&url=test.php")

Expected result:

  • The proxied script returns the same response for both requests

Actual result:

  • The response differs

Suggested fix:
Insert the following above the CURLOPT_FOLLOWLOCATION line:
// forward X-Requested-With header to ensure that if the server has an AJAX-specific response,
// it is preserved when using this proxy.
$headers_to_send = array();
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) $headers_to_send[] = 'X-Requested-With: ' . $_SERVER['HTTP_X_REQUESTED_WITH'];
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers_to_send );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant