/** * {@inheritdoc} */ public function createResponse(Application $application, Request $request, Socket $socket) : Response { if (!$request->hasHeader('Sec-WebSocket-Key')) { $sink = new MemorySink('No WebSocket key header provided.'); return new BasicResponse(Response::BAD_REQUEST, ['Connection' => 'close', 'Content-Length' => $sink->getLength()], $sink); } $headers = ['Connection' => 'upgrade', 'Upgrade' => 'websocket', 'Sec-WebSocket-Accept' => $this->responseKey(trim($request->getHeader('Sec-WebSocket-Key')))]; if ($application instanceof SubProtocol) { $protocol = $application->selectSubProtocol(array_map('trim', explode(',', $request->getHeader('Sec-WebSocket-Protocol')))); if (strlen($protocol)) { $headers['Sec-WebSocket-Protocol'] = $protocol; } } /* $extensions = $application->selectExtensions( array_map('trim', explode(',', $request->getHeader('Sec-WebSocket-Extensions'))) ); if (!empty($extensions)) { $headers['Sec-WebSocket-Extensions'] = $extensions; } */ $response = new BasicResponse(Response::SWITCHING_PROTOCOLS, $headers); $connection = $this->createConnection($response, $socket, false); return new WebSocketResponse($application, $connection, $response); }
public function hasBadWordpressTrackback() { // Fake WordPress trackbacks // Real ones do not contain Accept:, and have a charset defined // Real WP trackbacks may contain Accept: depending on the HTTP transport being used by the sending host return $this->request->hasHeader('content-type') && strpos($this->request->getUserAgent(), 'wordpress') !== false && strpos($this->request->getHeader('content-type'), 'charset=') !== false; }
/** * {@inheritdoc} */ public function buildOutgoingRequest(Request $request, float $timeout = 0, bool $allowPersistent = false) : \Generator { if (!$request->hasHeader('Connection')) { $request = $request->withHeader('Connection', $allowPersistent ? 'keep-alive' : 'close'); } if (!$request->hasHeader('Accept')) { $request = $request->withHeader('Accept', '*/*'); } if ($this->compressionEnabled) { $request = $request->withHeader('Accept-Encoding', 'gzip, deflate'); } else { $request = $request->withoutHeader('Accept-Encoding'); } return yield from $this->buildOutgoingStream($request, $timeout); }
/** * {@inheritDoc} */ public function hasHeader($header) { return $this->request->hasHeader($header); }