Beispiel #1
0
 /**
  * Send the Request
  *
  * @return Next\HTTP\Response|NULL
  *
  *   If an AdapterException is caught
  *   something is wrong with Response being send and thus NULL is returned
  *
  *   Otherwise, if everything is fine, a Next\HTTP\Response instance will
  *
  * @throws Next\HTTP\Request\RequestException
  *   No HTTP Stream Adapter provided
  *
  * @throws Next\HTTP\Headers\Fields\FieldsException
  *   Invalid or mal-formed Cookie (s) Value (s)
  *
  * @see Next\HTTP\Stream\Adapter\AdapterException
  */
 public function send()
 {
     // Setting Up a Fallback HTTP Stream Adapter
     if (is_null($this->adapter)) {
         $this->adapter = new Socket($this->uri, 'r', new SocketContext(array('http' => array('method' => $this->method))));
     }
     // Shortening HTTP Stream Context
     $context = $this->adapter->getContext();
     // Request Method
     $context->setOptions(array('http' => array('method' => $this->method)));
     //---------------
     // Request Method-related tasks
     switch ($this->method) {
         case self::GET:
             // Nothing so far...
             break;
         case self::POST:
             $this->sendPost();
             break;
         case self::PUT:
             // Nothing so far...
             break;
         case self::DELETE:
             // Nothing so far...
             break;
     }
     /**
      * @internal
      *
      * Cookies
      *
      * Cookies are defined in a Header Field too, so they come first
      */
     try {
         $this->headers->addHeader($this->cookies->getCookies(TRUE));
     } catch (FieldsException $e) {
         throw new RequestException($e->getMessage());
     }
     // Headers
     $context->setOptions(array('http' => array('header' => $this->headers->getHeaders(TRUE))));
     // Building Response
     try {
         $reader = new Reader($this->adapter);
         return new Response($reader->readAll(), $this->adapter->getMetaData());
     } catch (AdapterException $e) {
         return new Response();
     }
 }