Changeset View
Changeset View
Standalone View
Standalone View
src/future/http/HTTPSFuture.php
| Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | if (!$this->handle) { | ||||
| } else { | } else { | ||||
| $data = $this->formatRequestDataForCURL(); | $data = $this->formatRequestDataForCURL(); | ||||
| curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | ||||
| } | } | ||||
| $headers = $this->getHeaders(); | $headers = $this->getHeaders(); | ||||
| $saw_expect = false; | $saw_expect = false; | ||||
| $saw_accept = false; | |||||
| for ($ii = 0; $ii < count($headers); $ii++) { | for ($ii = 0; $ii < count($headers); $ii++) { | ||||
| list($name, $value) = $headers[$ii]; | list($name, $value) = $headers[$ii]; | ||||
| $headers[$ii] = $name.': '.$value; | $headers[$ii] = $name.': '.$value; | ||||
| if (!strncasecmp($name, 'Expect', strlen('Expect'))) { | if (!strcasecmp($name, 'Expect')) { | ||||
| $saw_expect = true; | $saw_expect = true; | ||||
| } | } | ||||
| if (!strcasecmp($name, 'Accept-Encoding')) { | |||||
| $saw_accept = true; | |||||
| } | |||||
| } | } | ||||
| if (!$saw_expect) { | if (!$saw_expect) { | ||||
| // cURL sends an "Expect" header by default for certain requests. While | // cURL sends an "Expect" header by default for certain requests. While | ||||
| // there is some reasoning behind this, it causes a practical problem | // there is some reasoning behind this, it causes a practical problem | ||||
| // in that lighttpd servers reject these requests with a 417. Both sides | // in that lighttpd servers reject these requests with a 417. Both sides | ||||
| // are locked in an eternal struggle (lighttpd has introduced a | // are locked in an eternal struggle (lighttpd has introduced a | ||||
| // 'server.reject-expect-100-with-417' option to deal with this case). | // 'server.reject-expect-100-with-417' option to deal with this case). | ||||
| // | // | ||||
| // The ostensibly correct way to suppress this behavior on the cURL side | // The ostensibly correct way to suppress this behavior on the cURL side | ||||
| // is to add an empty "Expect:" header. If we haven't seen some other | // is to add an empty "Expect:" header. If we haven't seen some other | ||||
| // explicit "Expect:" header, do so. | // explicit "Expect:" header, do so. | ||||
| // | // | ||||
| // See here, for example, although this issue is fairly widespread: | // See here, for example, although this issue is fairly widespread: | ||||
| // http://curl.haxx.se/mail/archive-2009-07/0008.html | // http://curl.haxx.se/mail/archive-2009-07/0008.html | ||||
| $headers[] = 'Expect:'; | $headers[] = 'Expect:'; | ||||
| } | } | ||||
| if (!$saw_accept) { | |||||
| if (!$use_streaming_parser) { | |||||
| if ($this->canAcceptGzip()) { | |||||
| $headers[] = 'Accept-Encoding: gzip'; | |||||
| } | |||||
| } | |||||
| } | |||||
| curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | ||||
| // Set the requested HTTP method, e.g. GET / POST / PUT. | // Set the requested HTTP method, e.g. GET / POST / PUT. | ||||
| curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->getMethod()); | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->getMethod()); | ||||
| // Make sure we get the headers and data back. | // Make sure we get the headers and data back. | ||||
| curl_setopt($curl, CURLOPT_HEADER, true); | curl_setopt($curl, CURLOPT_HEADER, true); | ||||
| curl_setopt($curl, CURLOPT_WRITEFUNCTION, | curl_setopt($curl, CURLOPT_WRITEFUNCTION, | ||||
| ▲ Show 20 Lines • Show All 503 Lines • ▼ Show 20 Lines | final class HTTPSFuture extends BaseHTTPFuture { | ||||
| protected function getServiceProfilerStartParameters() { | protected function getServiceProfilerStartParameters() { | ||||
| return array( | return array( | ||||
| 'type' => 'http', | 'type' => 'http', | ||||
| 'uri' => phutil_string_cast($this->getURI()), | 'uri' => phutil_string_cast($this->getURI()), | ||||
| ); | ); | ||||
| } | } | ||||
| private function canAcceptGzip() { | |||||
| return function_exists('gzdecode'); | |||||
| } | |||||
| } | } | ||||