/** * Manipulate Http Request * * @param iHttpRequest $request */ function withHttpRequest(iHttpRequest $request) { $params = \Poirot\Std\iterator_to_array($this); $body = json_encode($params); $request->setBody($body); $request->getHeaders()->set(HeaderFactory::factory('Content-Type', 'application/json')); }
/** * Manipulate Http Request * * @param iHttpRequest $request */ function withHttpRequest(iHttpRequest $request) { $params = \Poirot\Std\iterator_to_array($this); $body = http_build_query($params, null, '&'); $request->setBody($body); $request->getHeaders()->set(HeaderFactory::factory('Content-Type', 'application/x-www-form-urlencoded')); }
/** * Do Connect To Server With Streamable * * @param string $serverUrl * * @return iStreamable */ function doConnect($serverUrl) { // TODO validate scheme, ssl connection $parsedServerUrl = parse_url($serverUrl); $parsedServerUrl['scheme'] = 'tcp'; isset($parsedServerUrl['port']) ?: ($parsedServerUrl['port'] = 80); $serverUrl = $this->__unparse_url($parsedServerUrl); $stream = new StreamClient(\Poirot\Std\array_merge(\Poirot\Std\iterator_to_array($this->optsData()), ['socket_uri' => $serverUrl])); ### options // TODO watch getTimeout $stream->setTimeout($this->optsData()->getTimeout()); $stream->setPersist($this->optsData()->isPersist()); $resource = $stream->getConnect(); return new Streamable($resource); }