curl_writeheader_callback.phpt 798 B

12345678910111213141516171819202122232425262728293031
  1. --TEST--
  2. Test curl option CURLOPT_HEADERFUNCTION
  3. --CREDITS--
  4. Mathieu Kooiman <mathieuk@gmail.com>
  5. Dutch UG, TestFest 2009, Utrecht
  6. --DESCRIPTION--
  7. Hit the host and determine that the headers are sent to the callback specified for CURLOPT_HEADERFUNCTION. Different test servers might return different sets of headers. Just test for HTTP/1.1 200 OK.
  8. --EXTENSIONS--
  9. curl
  10. --FILE--
  11. <?php
  12. function curl_header_callback($curl_handle, $data)
  13. {
  14. if (strtolower(substr($data,0, 4)) == 'http')
  15. echo $data;
  16. }
  17. include 'server.inc';
  18. $host = curl_cli_server_start();
  19. $ch = curl_init();
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  21. curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'curl_header_callback');
  22. curl_setopt($ch, CURLOPT_URL, $host);
  23. curl_exec($ch);
  24. curl_close($ch);
  25. ?>
  26. --EXPECTF--
  27. HTTP/1.1 %d %s