private function setRequest() { $url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $request = new Request($url, $_SERVER['REQUEST_METHOD']); if (isset($_SERVER['HTTP_REFERRER'])) { $request->setReferrer($_SERVER['HTTP_REFERRER']); } $this->ip = $_SERVER['REMOTE_ADDR']; // $request->set ( $_SERVER ['REMOTE_ADDR'] ); $request->setBody(file_get_contents("php://input")); if ($request->getMethod() !== 'POST') { parse_str($request->getBody(), $post_vars); $request->setPost($post_vars); } else { $request->setPost($_POST); } foreach (getallheaders() as $k => $v) { $request->addHeader($k, $v); } $this->request = $request; }
/** * Returns true if the body of both specified requests match. * * @param Request $first First request to match. * @param Request $second Second request to match. * * @return boolean True if the body of both specified requests match. */ public static function matchBody(Request $first, Request $second) { if (null !== $first->getBody() && (string) $first->getBody() != (string) $second->getBody()) { return false; } return true; }
/** * Verify basic functionality of the request object. * * @test * @covers ::__construct * @covers ::getUrl * @covers ::getBody * @covers ::getMethod * @covers ::getHeaders * * @return void */ public function construct() { $url = 'a url'; $method = 'a method'; $body = ['some' => 'data']; $headers = ['key' => 'value']; $request = new Request($url, $method, $headers, $body); $this->assertSame($url, $request->getUrl()); $this->assertSame($method, $request->getMethod()); $this->assertSame($headers, $request->getHeaders()); $this->assertSame($body, $request->getBody()); }
public function Post(Request $request) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request->getUri()); curl_setopt($ch, CURLOPT_POST, 1); //0 for a get request curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $response = curl_exec($ch); $r = $this->ConvertCurlResponse($response, $ch); curl_close($ch); return $r; }
/** * Führt den Request aus * * Gibt die Ausgabe des Calls vom Controller zurück * wenn man den Request nicht selbst erstellen will, kann man * * \Psc\URL\Service\Request::infer(); * * benutzen. */ public function process(Request $request) { // required $service = $this->getRegisteredService($request->getPart(1)); $call = new Call(mb_strtolower($request->getMethod())); // identifier ist optional if (($identifier = $request->getPart(2)) !== NULL) { $call->addParameter($identifier); /* alle Subs weitergeben als weitere Parameter */ foreach ($request->getPartsFrom(3) as $p) { $call->addParameter($p); } } else { $call->setName('index'); } if ($request->getMethod() === Request::POST || $request->getMethod() === Request::PUT) { $call->addParameter($request->getBody()); } $this->call = $call; $this->service = $service; return $this->call(); }
public function __invoke(Request $request, Response $response, ...$args) { if ($request->getMethod() !== "GET") { $response->setStatus(HTTP_STATUS["METHOD_NOT_ALLOWED"]); $response->setHeader("Allow", "GET"); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } if ($request->getProtocolVersion() !== "1.1") { $response->setStatus(HTTP_STATUS["HTTP_VERSION_NOT_SUPPORTED"]); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } $body = $request->getBody(); if (!$body instanceof NullBody) { $response->setStatus(HTTP_STATUS["BAD_REQUEST"]); $response->setReason("Bad Request: Entity body disallowed for websocket endpoint"); $response->setHeader("Connection", "close"); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } $hasUpgradeWebsocket = false; foreach ($request->getHeaderArray("Upgrade") as $value) { if (strcasecmp($value, "websocket") === 0) { $hasUpgradeWebsocket = true; break; } } if (empty($hasUpgradeWebsocket)) { $response->setStatus(HTTP_STATUS["UPGRADE_REQUIRED"]); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } $hasConnectionUpgrade = false; foreach ($request->getHeaderArray("Connection") as $value) { $values = array_map("trim", explode(",", $value)); foreach ($values as $token) { if (strcasecmp($token, "Upgrade") === 0) { $hasConnectionUpgrade = true; break; } } } if (empty($hasConnectionUpgrade)) { $response->setStatus(HTTP_STATUS["UPGRADE_REQUIRED"]); $response->setReason("Bad Request: \"Connection: Upgrade\" header required"); $response->setHeader("Upgrade", "websocket"); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } if (!($acceptKey = $request->getHeader("Sec-Websocket-Key"))) { $response->setStatus(HTTP_STATUS["BAD_REQUEST"]); $response->setReason("Bad Request: \"Sec-Websocket-Key\" header required"); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } if (!in_array("13", $request->getHeaderArray("Sec-Websocket-Version"))) { $response->setStatus(HTTP_STATUS["BAD_REQUEST"]); $response->setReason("Bad Request: Requested Websocket version unavailable"); $response->setHeader("Sec-WebSocket-Version", "13"); $response->setHeader("Aerys-Generic-Response", "enable"); $response->end(); return; } $handshaker = new Handshake($response, $acceptKey); $onHandshakeResult = $this->application->onHandshake($request, $handshaker, ...$args); if ($onHandshakeResult instanceof \Generator) { $onHandshakeResult = (yield from $onHandshakeResult); } $request->setLocalVar("aerys.websocket", $onHandshakeResult); $handshaker->end(); }
/** * Returns true if the body of both specified requests match. * * @param Request $first First request to match. * @param Request $second Second request to match. * * @return boolean True if the body of both specified requests match. */ public static function matchBody(Request $first, Request $second) { return $first->getBody() === $second->getBody(); }
/** * {@inheritDoc} */ public function getBody() { return $this->request->getBody(); }
public function testConstructBodyNull() { $request = new Request("http://www.fabysdev.com", "get", null); $this->assertNull($request->getBody()); }
/** * @param Request $request * * @return mixed */ public function getPath(Request $request) { return $request->getBody()['act']; }