protected function makeResult($response, $method) {
    //Make sure we got the complete response.
    if(
      $method != 'HEAD' &&
      isset($response->headers->{'content-length'}) &&
      strlen($response->body) != $response->headers->{'content-length'}
    ) {
      throw new SagException('Unexpected end of packet.');
    }

    /*
     * HEAD requests can return an HTTP response code >=400, meaning that there
     * was a CouchDB error, but we don't get a $response->body->error because
     * HEAD responses don't have bodies.
     *
     * We do this before the json_decode() because even running json_decode()
     * on undefined can take longer than calling it on a JSON string. So no
     * need to run any of the $json code.
     */
    if($method == 'HEAD') {
      if($response->status >= 400) {
        throw new SagCouchException('HTTP/CouchDB error without message body', $response->headers->_HTTP->status);
      }

      return $response;
    }

    // Decode whether they ask for a raw response or not for error messages.
    if(
      !empty($response->headers->{'content-type'}) &&
      $response->headers->{'content-type'} == 'application/json'
    ) {
      $json = json_decode($response->body);

      if(isset($json)) {
        if(!empty($json->error)) {
          throw new SagCouchException("{$json->error} ({$json->reason})", $response->headers->_HTTP->status);
        }

        if($this->decodeResp) {
          $response->body = $json;
        }
      }
    }

    return $response;
  }
protected function makeResult($response, $method) {
    //Make sure we got the complete response.
    if(
      $method != 'HEAD' &&
      isset($response->headers->{'content-length'}) &&
      strlen($response->body) != $response->headers->{'content-length'}
    ) {
      throw new SagException('Unexpected end of packet.');
    }

    /*
     * HEAD requests can return an HTTP response code >=400, meaning that there
     * was a CouchDB error, but we don't get a $response->body->error because
     * HEAD responses don't have bodies.
     *
     * We do this before the json_decode() because even running json_decode()
     * on undefined can take longer than calling it on a JSON string. So no
     * need to run any of the $json code.
     */
    if($method == 'HEAD') {
      if($response->status >= 400) {
        throw new SagCouchException('HTTP/CouchDB error without message body', $response->headers->_HTTP->status);
      }

      return $response;
    }

    // Decode whether they ask for a raw response or not for error messages.
    if(
      !empty($response->headers->{'content-type'}) &&
      $response->headers->{'content-type'} == 'application/json'
    ) {
      $json = json_decode($response->body);

      if(isset($json)) {
        if(!empty($json->error)) {
          throw new SagCouchException("{$json->error} ({$json->reason})", $response->headers->_HTTP->status);
        }

        if($this->decodeResp) {
          $response->body = $json;
        }
      }
    }

    return $response;
  }
protected function makeResult ( $ response , $ method ) { //Make sure we got the complete response. if ( $ method != 'HEAD' && isset ( $ response -> headers -> { 'content-length' } ) && strlen ( $ response -> body ) != $ response -> headers -> { 'content-length' } ) { throw new SagException ( 'Unexpected end of packet.' ) ; } /*
     * HEAD requests can return an HTTP response code >=400, meaning that there
     * was a CouchDB error, but we don't get a $response->body->error because
     * HEAD responses don't have bodies.
     *
     * We do this before the json_decode() because even running json_decode()
     * on undefined can take longer than calling it on a JSON string. So no
     * need to run any of the $json code.
     */ if ( $ method == 'HEAD' ) { if ( $ response -> status >= 400 ) { throw new SagCouchException ( 'HTTP/CouchDB error without message body' , $ response -> headers -> _HTTP -> status ) ; } return $ response ; } // Decode whether they ask for a raw response or not for error messages. if ( ! empty ( $ response -> headers -> { 'content-type' } ) && $ response -> headers -> { 'content-type' } == 'application/json' ) { $ json = json_decode ( $ response -> body ) ; if ( isset ( $ json ) ) { if ( ! empty ( $ json -> error ) ) { throw new SagCouchException ( "{$json->error} ({$json->reason})" , $ response -> headers -> _HTTP -> status ) ; } if ( $ this -> decodeResp ) { $ response -> body = $ json ; } } } return $ response ; }
Used by the concrete HTTP adapters, this abstracts out the generic task of
turning strings from the net into response objects.

@param string $response The body of the HTTP packet.
@param string $method The request's HTTP method ("HEAD", etc.).
@returns stdClass The response object.
Used by the concrete HTTP adapters this abstracts out the generic task of turning strings from the net into response objects .