Get an existing client or create a new client to handle HTTP request.
338757
private Client getClient() {
        Client client = hostMap.get(basePath);
        if (client!=null) return client;

        final ClientConfig clientConfig = new ClientConfig();
        clientConfig.register(MultiPartFeature.class);
        if (debug) {
            clientConfig.register(LoggingFilter.class);
        }
        client = ClientBuilder.newClient(clientConfig);

        hostMap.putIfAbsent(basePath, client);
        return hostMap.get(basePath); //be sure to use the same in case of a race condition.
    }
63855
def client_new():
    """"""
    form = ClientForm(request.form)

    if form.validate_on_submit():
        c = Client(user_id=current_user.get_id())
        c.gen_salt()
        form.populate_obj(c)
        db.session.add(c)
        db.session.commit()
        return redirect(url_for('.client_view', client_id=c.client_id))

    return render_template(
        'invenio_oauth2server/settings/client_new.html',
        form=form,
    )
743348
function Client(opts) {
    if (!(this instanceof Client)) {
        return new Client(opts);
    }

    var options = {};

    // If single connection provided, array-ify it
    if (typeof opts === 'string') {
        options.hosts = [opts];
        opts = options;
    } else if (typeof opts === 'undefined') {
        opts = {};
    } else if (_.isArray(opts)) {
        options.hosts = opts;
        opts = options;
    }

    _.defaults(opts, {
        autodiscover: false,
        bufferBeforeError: 1000,
        disabled: false,
        hosts: null,
        reconnect: true,
        onNetError: function onNetError(err) { console.error(err); },
        queue: true,
        netTimeout: 500,
        backoffLimit: 10000,
        maxValueSize: 1048576
    });

    // Iterate over options, assign each to this object
    R.keys(opts).forEach(function(key) {
        this[key] = opts[key];
    }, this);

    if (this.queue) {
        this.buffer = new Immutable.List();
    }

    debug('Connect options', opts);
    this.connect();
}
832261
def client(self):
        """"""
        if self._client is None:
            self._client = self._client_builder()
        return self._client
703990
def get_client(self, provider):
        ""
        if self.client_class is not None:
            return self.client_class(provider)
        return get_client(provider)
1228950
def _build_client(self, name=None):
        
        url_path = self._url_path + [name] if name else self._url_path
        return Client(host=self.host,
                      version=self._version,
                      request_headers=self.request_headers,
                      url_path=url_path,
                      append_slash=self.append_slash,
                      timeout=self.timeout)
434750
protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
		ClientHttpRequest request = getRequestFactory().createRequest(url, method);
		if (Log.isLoggable(TAG, Log.DEBUG)) {
			Log.d(TAG, "Created " + method.name() + " request for \"" + url + "\"");
		}
		return request;
	}
1110650
public static HttpClient getNewHttpClient(String uri, ClientConnectionManager connectionManager) {
        try {

            HttpParams params = new BasicHttpParams();
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

            final DefaultHttpClient result = new DefaultHttpClient(
                    connectionManager, params);
            configureProxy(uri, result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new DefaultHttpClient();
        }
    }
369004
public <T> HttpClientRequest.Builder<T> options(final URI uri, final HttpClientResponseHandler<T> httpHandler)
    {
        return new HttpClientRequest.Builder<T>(httpClientFactory, HttpClientMethod.OPTIONS, uri, httpHandler);
    }
670063
protected function getClient(): HttpClient
    {
        if ($this->_client == null) {
            $this->_client = new HttpClient(['base_uri' => $this->_endpoint]);
        }

        return $this->_client;
    }
185475
def request(self, method, path, **options):
        """"""
        options = self._merge_options(options)
        url = options['base_url'] + path
        retry_count = 0
        request_options = self._parse_request_options(options)
        self._add_version_header(request_options)
        while True:
            try:
                response = getattr(self.session, method)(
                    url, auth=self.auth, **request_options)
                if response.status_code in STATUS_MAP:
                    raise STATUS_MAP[response.status_code](response)
                elif 500 <= response.status_code < 600:
                    # Any unhandled 500 is a server error.
                    raise error.ServerError(response)
                else:
                    if options['full_payload']:
                        return response.json()
                    else:
                        return response.json()['data']
            except error.RetryableAsanaError as e:
                if retry_count < options['max_retries']:
                    self._handle_retryable_error(e, retry_count)
                    retry_count += 1
                else:
                    raise e
692427
def request(self, *args, **kwargs):
        """"""
        try:
            return self._http.request(*args, timeout=TIMEOUT, **kwargs)
        except Exception as exc:
            raise RequestException(exc, args, kwargs)
301631
public <T> HttpClientRequest.Builder<T> get(final URI uri, final HttpClientResponseHandler<T> httpHandler)
    {
        return new HttpClientRequest.Builder<T>(httpClientFactory, HttpClientMethod.GET, uri, httpHandler);
    }
381156
function Request (opts) {
  var self = this
  if (!(self instanceof Request)) return new Request(opts)
  if (!opts) opts = {}

  self.HTTPMethod = opts.method
  self.HTTPHeaders = {}
  self.opts = opts

  if (opts.method === 'POST') {
    if (opts.endpoint) {
      self._initPOST(opts)
    } else if (opts.url) {
      self._initPOSTURL(opts)
    } else {
      throw new Error('invalid request')
    }
  } else if (opts.method === 'GET') {
    self._initGET(opts)
  } else {
    throw new Error('invalid request')
  }
}
1064631
async def _request(self, *, http_verb, api_url, req_args):
        
        if self.session and not self.session.closed:
            async with self.session.request(http_verb, api_url, **req_args) as res:
                self._logger.debug("Ran the request with existing session.")
                return {
                    "data": await res.json(),
                    "headers": res.headers,
                    "status_code": res.status,
                }
        async with aiohttp.ClientSession(
            loop=self._event_loop, timeout=aiohttp.ClientTimeout(total=self.timeout)
        ) as session:
            async with session.request(http_verb, api_url, **req_args) as res:
                self._logger.debug("Ran the request with a new session.")
                return {
                    "data": await res.json(),
                    "headers": res.headers,
                    "status_code": res.status,
                }
35888
protected HttpClient newHttpClient() {
        return HttpClients.custom()
                // Do not manage redirection.
                .setRedirectStrategy(new DefaultRedirectStrategy() {
                    @Override
                    protected boolean isRedirectable(String method) {
                        return followRedirect(method);
                    }
                })
                .setDefaultCookieStore(new BasicCookieStore() {
                    @Override
                    public synchronized List<Cookie> getCookies() {
                        return Collections.emptyList();
                    }
                })
                .build();
    }
667421
async def _request(
            self, method: str, endpoint: str, *, headers: dict = None) -> dict:
        """"""
        url = '{0}/{1}'.format(API_URL_SCAFFOLD, endpoint)

        if not headers:
            headers = {}
        headers.update({
            'Host': DEFAULT_HOST,
            'Origin': DEFAULT_ORIGIN,
            'Referer': DEFAULT_ORIGIN,
            'User-Agent': DEFAULT_USER_AGENT,
        })

        async with self._websession.request(
                method,
                url,
                headers=headers,
        ) as resp:
            try:
                resp.raise_for_status()
                return await resp.json(content_type=None)
            except client_exceptions.ClientError as err:
                raise RequestError(
                    'Error requesting data from {0}: {1}'.format(
                        endpoint, err)) from None