How to use the cross-fetch.Headers function in cross-fetch

To help you get started, we’ve selected a few cross-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github badgateway / ketting / src / resource.js View on Github external
if (input === undefined) {
      // Nothing was provided, we're operating on the resource uri.
      uri = this.uri;
    } else if (typeof input === 'string') {
      // If it's a string, it might be relative uri so we're resolving it
      // first.
      uri = url.resolve(this.uri, input);

    } else if (input instanceof fetch.Request) {
      // We were passed a request object. We need to extract all its
      // information into the init object.
      uri = url.resolve(this.uri, input.url);

      newInit.method = input.method;
      newInit.headers = new fetch.Headers(input.headers);
      newInit.body = input.body;
      newInit.mode = input.mode;
      newInit.credentials = input.credentials;
      newInit.cache = input.cache;
      newInit.redirect = input.redirect;
      newInit.referrer = input.referrer;
      newInit.integrity = input.integrity;

    } else if (input instanceof Object) {
      // if it was a regular 'object', but not a Request, we're assuming the
      // method was called with the init object as it's first parameter. This
      // is not allowed in the default Fetch API, but we do allow it because
      // in the resource, specifying the uri is optional.
      uri = this.uri;
      newInit = input;
    } else {
github badgateway / ketting / src / utils / fetch-helper.ts View on Github external
function mergeHeaders(headerSets: HeaderSet[]): any {

  var result = new crossFetch.Headers();
  for(const headerSet of headerSets) {

    if (headerSet instanceof crossFetch.Headers) {
      for(var key of headerSet.keys()) {
        result.set(key, headerSet.get(key));
      }
    } else if (headerSet) {
      // not falsey, must be a key->value object.
      for(var index in headerSet) {
        result.set(index, headerSet[key]);
      }
    }
  }

  return result;