private function addExpectHeader(puzzle_message_RequestInterface $request, puzzle_stream_StreamInterface $body) { // Determine if the Expect header should be used if ($request->hasHeader('Expect')) { return; } $expect = $request->getConfig(); $expect = $expect['expect']; // Return if disabled or if you're not using HTTP/1.1 if ($expect === false || $request->getProtocolVersion() !== '1.1') { return; } // The expect header is unconditionally enabled if ($expect === true) { $request->setHeader('Expect', '100-Continue'); return; } // By default, send the expect header when the payload is > 1mb if ($expect === null) { $expect = 1048576; } // Always add if the body cannot be rewound, the size cannot be // determined, or the size is greater than the cutoff threshold $size = $body->getSize(); if ($size === null || $size >= (int) $expect || !$body->isSeekable()) { $request->setHeader('Expect', '100-Continue'); } }
/** * Create a redirect request for a specific request object * * Takes into account strict RFC compliant redirection (e.g. redirect POST * with POST) vs doing what most clients do (e.g. redirect POST with GET). * * @param puzzle_message_RequestInterface $request * @param puzzle_message_ResponseInterface $response * * @return puzzle_message_RequestInterface Returns a new redirect request * @throws puzzle_exception_CouldNotRewindStreamException If the body cannot be rewound. */ private function createRedirectRequest(puzzle_message_RequestInterface $request, puzzle_message_ResponseInterface $response) { $config = $request->getConfig(); // Use a GET request if this is an entity enclosing request and we are // not forcing RFC compliance, but rather emulating what all browsers // would do. Be sure to disable redirects on the clone. $redirectRequest = clone $request; $redirectRequest->getEmitter()->detach($this); $statusCode = $response->getStatusCode(); if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) { $redirectRequest->setMethod('GET'); $redirectRequest->setBody(null); } $this->setRedirectUrl($redirectRequest, $response); $this->rewindEntityBody($redirectRequest); // Add the Referer header if it is told to do so and only // add the header if we are not redirecting from https to http. if ($config->getPath('redirect/referer') && ($redirectRequest->getScheme() == 'https' || $redirectRequest->getScheme() == $request->getScheme())) { $url = puzzle_Url::fromString($request->getUrl()); $url->setUsername(null)->setPassword(null); $redirectRequest->setHeader('Referer', (string) $url); } return $redirectRequest; }
private function add_decode_content(puzzle_message_RequestInterface $request, $value) { if ($value === false) { return; } if ($value !== true) { $request->setHeader('Accept-Encoding', $value); } $config = $request->getConfig(); $config['decode_content'] = true; }
private function applyTransferOptions(puzzle_message_RequestInterface $request, puzzle_adapter_curl_RequestMediator $mediator) { static $methods; if (!$methods) { $methods = array_flip(get_class_methods(__CLASS__)); } foreach ($request->getConfig()->toArray() as $key => $value) { $method = "add_{$key}"; if (isset($methods[$method])) { $this->{$method}($request, $mediator, $value); } } }
private function applyCustomOptions(puzzle_message_RequestInterface $request, array &$options) { // Overwrite any generated options with custom options $config = $request->getConfig(); if ($custom = $config['stream_context']) { if (!is_array($custom)) { throw new puzzle_exception_AdapterException('stream_context must be an array'); } $options = __puzzle_array_replace_recursive($options, $custom); } }
/** * {@inheritdoc} */ public function setConfig(array $config) { $this->_delegate->getConfig()->clear(); $this->_delegate->getConfig()->merge($config); }