Intermediate function which does three main things

- Transforms the body of request into correct format
- Creates the requests with give parameters
- Returns response body after parsing it into correct format
496224
public function request($path, $body = null, $httpMethod = 'GET', array $options = array())
    {
        $headers = array();

        $options = array_merge($this->options, $options);

        if (isset($options['headers'])) {
            $headers = $options['headers'];
            unset($options['headers']);
        }

        $headers = array_merge($this->headers, array_change_key_case($headers));

        unset($options['body']);

        unset($options['base']);
        unset($options['user_agent']);

        $request = $this->createRequest($httpMethod, $path, null, $headers, $options);

        if ($httpMethod != 'GET') {
            $request = $this->setBody($request, $body, $options);
        }

        try {
            $response = $this->client->send($request);
        } catch (\LogicException $e) {
            throw new \ErrorException($e->getMessage());
        } catch (\RuntimeException $e) {
            throw new \RuntimeException($e->getMessage());
        }

        return new Response($this->getBody($response), $response->getStatusCode(), $response->getHeaders());
    }
1088932
def prepare_request(self, method, url, body=''):
        
        headers = {
            'Content-type': 'application/json',
        }
        # Note: we don't pass body to sign() since it's only for bodies that
        # are form-urlencoded. Similarly, we don't care about the body that
        # sign() returns.
        uri, signed_headers, signed_body = self.oauth_client.sign(
            url, http_method=method, headers=headers)
        if body:
            if method == 'GET':
                body = urllib.urlencode(body)
            else:
                body = json.dumps(body)
        headers.update(signed_headers)
        return {"headers": headers, "data": body}
1123042
function makeRequest () {
    request = self.request.apply(null, args);
    requestMiddleware.use(request);
    request.on("response", function (response) {
      var contentEncoding, gzipper;

      //Only cache successful responses
      if (response.statusCode >= 200 && response.statusCode < 300) {
        response.on('error', function (error) {
          self.handleError(error);
        });
        fs.writeFile(self.cacheDirectory + key + ".json", JSON.stringify(response.headers), function (error) {
          if (error) self.handleError(error);
        });

        responseWriter = fs.createWriteStream(self.cacheDirectory + key);

        responseWriter.on('error', function (error) {
          self.handleError(error);
        });

        contentEncoding = response.headers['content-encoding'] || '';
        contentEncoding = contentEncoding.trim().toLowerCase();

        if (contentEncoding === 'gzip') {
          response.on('error', function (error) {
            responseWriter.end();
          });
          response.pipe(responseWriter);
        } else {
          gzipper = zlib.createGzip();
          response.on('error', function (error) {
            gzipper.end();
          });
          gzipper.on('error', function (error) {
            self.handleError(error);
            responseWriter.end();
          });
          responseWriter.on('error', function (error) {
            response.unpipe(gzipper);
            gzipper.end();
          });
          response.pipe(gzipper).pipe(responseWriter);
        }
      }
    });
    self.emit("request", args[0]);
  }
235010
function makeRequest(){
  output('Sending the request...');
  var options = {
    method: $method.value,
    headers: {
      Accept: document.getElementById('accept').value
    },
    followRedirect: $followRedirect.checked
  };
  if(options.method === 'POST'){
    options.body = $requestBody.value;
  }
  client.request($url.value, options, function(error, response){
    if(error){
      genericError();
    } else {
      displayResponse(response);
      
      if(response.statusCode === 401){
        $authStatus.classList.remove('loggedin');
        $tokenDisplay.value = '';
        
      } else {
        $authStatus.classList.add('loggedin');
        $tokenDisplay.value = 'Bearer ' + client.getAccessToken();
      }
    }
  });
}
1282135
function request (url, options) {
  options = Object.assign({}, defaultOptions, options)
  let savedContent
  let savedResponse

  return new Promise((resolve, reject) => {
    fetch(url, options)
      .then(handleResponse)
      .then(handleBody)
      .catch(handleError)

    function handleResponse (response) {
      // Save the response for checking the status later
      savedResponse = response

      // Decode the response body
      switch (options.type) {
        case 'response':
          return response
        case 'json':
          return response.json()
        default:
          return response.text()
      }
    }

    function handleBody (content) {
      // Bubble an error if the response status is not okay
      if (savedResponse && savedResponse.status >= 400) {
        savedContent = content
        throw new Error(`Response status indicates error`)
      }

      // All is well!
      resolve(content)
    }

    function handleError (err) {
      // Overwrite potential decoding errors when the actual problem was the response
      if (savedResponse && savedResponse.status >= 400) {
        err = new Error(`Status ${savedResponse.status}`)
      }

      // Enrich the error message with the response and the content
      let error = new Error(err.message)
      error.response = savedResponse
      error.content = savedContent
      reject(error)
    }
  })
}
455807
function transform(req, res, next) {
    const state = res.state;
    const body = state.body;
    const type = typeof body;
    const isBuffer = body instanceof Buffer;
    let contentType;

    // error conversion
    if (body instanceof Error) {
        res.log('transform', 'Converting Error to response');
        res.status(500).body(httpStatus[500]).set('content-type', 'text/plain');

    // buffer conversion
    } else if (isBuffer) {
        res.log('transform', 'Converting Buffer to base64 string');
        res.body(body.toString('base64'));
        contentType = 'application/octet-stream';

    // object conversion
    } else if (type === 'object') {
        res.log('transform', 'Converting object to JSON string');
        res.body(JSON.stringify(body));
        contentType = 'application/json';

    // not string conversion
    } else if (type !== 'string') {
        res.log('transform', 'Converting ' + type + ' to string');
        res.body(String(body));
        contentType = 'text/plain';

    } else {
        contentType = 'text/html';
    }

    // set content type if not yet set
    if (!state.headers.hasOwnProperty('content-type') && contentType) {
        res.log('transform', 'Set content type');
        res.set('Content-Type', contentType);
    }

    next();
}
954693
function processResponse(err, res, body) {

    if (err) { return cb(err); }

    if (res.statusCode !== 200) {
      return cb(new ScrapeError('Not OK response from server.', res, body));
    }

    parseBody(body, model, options, cb);

  }
248638
def request(self, url, params={}, headers={}):
        
        # Generate current config. Merge in any given headers
        cur_config = self.config.copy()
        if 'headers' in cur_config:
            cur_config['headers'] = cur_config['headers'].copy()
            cur_config['headers'].update(headers)
        else:
            cur_config['headers'] = headers

        with closing(requests.get(url, params=params, **cur_config)) as response:
            if response.status_code == requests.codes.OK:
                # Prepare the temp file. xml content will be
                # stored in a binary file, json in a textfile.
                if (response.headers.get('Content-Type')
                        and ('json' in response.headers['Content-Type'])):
                    enc, fmode = response.encoding, 'w+t'
                else:
                    enc, fmode = None, 'w+b'
                # Create temp file ensuring 2to3 compatibility
                if str_type == str:  # we are on py3
                    source = STF(
                        max_size=self.max_size, mode=fmode, encoding=enc)
                else:
                    # On py27 we must omit the 'encoding' kwarg
                    source = STF(max_size=self.max_size, mode=fmode)
                for c in response.iter_content(chunk_size=1000000,
                                               decode_unicode=bool(enc)):
                    source.write(c)

            else:
                source = None
            code = int(response.status_code)
            if 400 <= code <= 499:
                raise response.raise_for_status()
            return source, response.url, response.headers, code
1072418
def _create(self, uri, body, return_none=False, return_raw=False,
            return_response=None, **kwargs):
        
        self.run_hooks("modify_body_for_create", body, **kwargs)
        resp, resp_body = self.api.method_post(uri, body=body)
        if return_none:
            # No response body
            return
        elif return_response:
            return resp
        elif return_raw:
            if self.response_key:
                return resp_body[self.response_key]
            else:
                return resp_body
        return self.resource_class(self, resp_body, self.response_key)
1307762
function makeRequest(options, callback) {
    request(options, function (error, response, body){
        if (error) {
            callback(error, null);
        }
        else if (response.statusCode == 200) {
            callback( null, JSON.parse(body));
        }
        else {
            callback(new Error('HTTP Response Code: ' + response.statusCode), null);
        }
    });
}
1893
def request(method, path, options, format)
      begin
        response = connection(format).send(method) do |request|
          case method.to_sym
          when :get, :delete
            request.url(formatted_path(path, format), options)
          when :post, :put
            request.path = formatted_path(path, format)
            request.body = options unless options.empty?
          end
      end
        'raw' == format.to_s.downcase ? response : response.body
      rescue MultiJson::DecodeError
        Hashie::Mash.new
      end
    end
245886
def convert_response(response)
      HttpResponse.new(response.status, response.headers, response.body)
    end
748145
def process_request(self, request):
        
        content_type = request.META.get('CONTENT_TYPE', '')
        for non_cacheable_type in self.non_cacheable_types:
            if non_cacheable_type in content_type:
                return
        request.body
249827
def raw(body, status=200, headers=None,
        content_type='application/octet-stream'):
    '''
    
    '''
    return HTTPResponse(body_bytes=body, status=status, headers=headers,
                        content_type=content_type)
510815
def make_response(body, mimetype='text/html'):
    
    from werkzeug.wrappers import Response
    if isinstance(body, Response):
        body.mimetype = mimetype
        return body
    return Response(body, mimetype=mimetype)
998873
def make_request(method, path, options, raw=false)
      options.merge!({:key => api_key, :id => api_id })

      response = connection(raw).send(method) do |request|
        case method
        when :get, :delete
          request.url(path, options)
        when :post, :put
          request.path = path
          request.body = options unless options.empty?
        end
      end
      return response if raw
      return response.body
    end
848640
def handle_intermediate_response(self, item_session: ItemSession) -> Actions:
        '''
        '''
        self._waiter.reset()

        action = self.handle_response(item_session)

        return action