Sha256: 8b94ec428f9dcd7d79c4c850917573e3295928b3c522490aac9265c7bc35c727

Contents?: true

Size: 1.41 KB

Versions: 56

Compression:

Stored size: 1.41 KB

Contents

HAL.Http.Client = function(opts) {
  this.vent = opts.vent;
  this.defaultHeaders = { 'Accept': 'application/hal+json, application/json, */*; q=0.01', 'X-Interface': 'HAL Browser' }; //pact_broker
  cookie = document.cookie.match('(^|;)\\s*' + 'MyHalBrowserToken' + '\\s*=\\s*([^;]+)');
  cookie ? this.defaultHeaders.Authorization = 'Bearer ' + cookie.pop() : '';
  this.headers = this.defaultHeaders;
};

HAL.Http.Client.prototype.get = function(url) {
  var self = this;
  this.vent.trigger('location-change', { url: url });
  var jqxhr = $.ajax({
    url: url,
    dataType: 'json',
    xhrFields: {
      withCredentials: false
    },
    headers: this.headers,
    success: function(resource, textStatus, jqXHR) {
      self.vent.trigger('response', {
        resource: resource,
        jqxhr: jqXHR,
        headers: jqXHR.getAllResponseHeaders()
      });
    }
  }).error(function() {
    self.vent.trigger('fail-response', { jqxhr: jqxhr });
  });
};

HAL.Http.Client.prototype.request = function(opts) {
  var self = this;
  opts.dataType = 'json';
  opts.xhrFields = opts.xhrFields || {};
  opts.xhrFields.withCredentials = opts.xhrFields.withCredentials || false;
  self.vent.trigger('location-change', { url: opts.url });
  return jqxhr = $.ajax(opts);
};

HAL.Http.Client.prototype.updateHeaders = function(headers) {
  this.headers = headers;
};

HAL.Http.Client.prototype.getHeaders = function() {
  return this.headers;
};

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
pact_broker-2.93.2 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.93.1 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.93.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.92.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.91.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.90.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.89.1 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.89.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.88.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.87.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.86.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.85.1 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.85.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.84.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.83.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.82.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.81.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.80.0 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.79.1 vendor/hal-browser/js/hal/http/client.js
pact_broker-2.79.0 vendor/hal-browser/js/hal/http/client.js