Example #1
0
  _setupRequest() {
    if (this._request) {
      return;
    }

    const user = this._connection.user();
    const headers = Object.assign({}, this._headers);

    const query = formatQuery(this._query, {
      allowDots: true,
      arrayFormat: 'repeat'
    });

    const path = this._path + (query.length > 0 ?
      '?' + query : '');

    if (this._method !== 'GET' && this._connection.codec()) {
      headers['Content-Type'] = this._connection.codec().type;
    }

    if (user !== null) {
      headers.Authorization = 'Bearer ' + user.token();
    }

    this._request = this._connection.http().request({
      host: this._host,
      headers,
      method: this._method,
      path,
      port: this._port,
      withCredentials: false
    });

    this._bindRequest();
  }
Example #2
0
  _mpq() {
    const query = formatQuery(this._query, {
      allowDots: true,
      arrayFormat: 'repeat'
    });

    return this._method + ' ' +
      this._path +
      (query.length > 0 ? '?' + query : '');
  }