コード例 #1
0
ファイル: AwsQueryVisitor.php プロジェクト: loulancn/core
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $this->fqname = $command->getName();
     $query = array();
     $this->customResolver($value, $param, $query, $param->getWireName());
     $request->addPostFields($query);
 }
コード例 #2
0
 public static function setBody(RequestInterface $request, $body, $options)
 {
     $type = isset($options['request_type']) ? $options['request_type'] : 'form';
     $header = null;
     if ($type == 'form') {
         // Encoding body into form-urlencoded format
         return $request->addPostFields($body);
     }
     if ($type == 'raw') {
         // Raw body
         return $request->setBody($body, $header);
     }
 }
コード例 #3
0
 protected function onRequest(ConnectionInterface $from, RequestInterface $request)
 {
     $requestPath = $request->getPath();
     $body = (string) $request->getBody();
     if (!empty($body)) {
         $query = QueryString::fromString($body);
         $fields = $query->getAll();
         $request->addPostFields($fields);
     }
     // TODO: use only $req->acceptLanguage() in Managers
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = (string) $request->getHeaders()->get('accept-language');
     $routes = array('/' => 'executeUiBooter', '/api' => 'executeApiCall', '/api/group' => 'executeApiCallGroup', '/sbin/apicall.php' => 'executeApiCall', '/sbin/apicallgroup.php' => 'executeApiCallGroup', '/sbin/rawdatacall.php' => 'executeRawDataCall', '#^/([a-zA-Z0-9-_.]+)\\.html$#' => 'executeUiBooter', '#^/(bin|boot|etc|home|tmp|usr|var)/(.*)$#' => 'executeReadFile', '/webos.webapp' => 'executeReadManifest', '/hello' => 'executeSayHello');
     foreach ($routes as $path => $method) {
         $matched = false;
         if (substr($path, 0, 1) == '#') {
             // Regex
             if (preg_match($path, $requestPath, $matches)) {
                 $result = $this->{$method}($from, $request, $matches);
                 $matched = true;
             }
         } else {
             if ($path == $requestPath) {
                 $result = $this->{$method}($from, $request);
                 $matched = true;
             }
         }
         if ($matched) {
             if (empty($result)) {
                 $result = '';
             }
             if ($result instanceof ResponseContent) {
                 $result = $result->generate();
             }
             if ($result instanceof HTTPServerResponse) {
                 if ($result->headersSent()) {
                     // Implicit mode, content already sent
                     if ($result->getHeader('Connection') != 'keep-alive') {
                         $from->close();
                     }
                 } else {
                     $result->send();
                 }
                 return;
             }
             $response = null;
             if (is_string($result)) {
                 $response = new Response(200, array(), (string) $result);
             } else {
                 $response = $result;
             }
             $from->send((string) $response);
             $from->close();
             return;
         }
     }
     $resp = new Response(404, array('Content-Type' => 'text/plain'), '404 Not Found');
     $from->send((string) $resp);
     $from->close();
 }
コード例 #4
0
 private function configureRequest(RequestInterface $request, array $server, array $enclosure)
 {
     if (isset($server['HTTP_HOST'])) {
         $request->setHost($server['HTTP_HOST']);
     }
     if (isset($server['HTTP_PORT'])) {
         $request->setPort($server['HTTP_PORT']);
     }
     if (isset($server['PHP_AUTH_USER'])) {
         $request->setAuth($server['PHP_AUTH_USER'], isset($server['PHP_AUTH_PW']) ? $server['PHP_AUTH_PW'] : null);
     }
     $params = [];
     if (isset($server['HTTP_USER_AGENT'])) {
         $params['userAgent'] = $server['HTTP_USER_AGENT'];
     }
     if ($request instanceof EntityEnclosingRequestInterface) {
         $request->addPostFields($enclosure);
     }
     return $params;
 }