title: Angular interceptor to set header authorization causes error in return of api
body: <p>I have created an interceptor to set the header authorization:</p>
  
  <pre><code>.config(['$httpProvider', function($httpProvider) {
      var httpAuthInterceptor = [ 'AuthStateService', function(AuthStateService) {
        return {
          'request': function(config) {
            var user = AuthStateService.getCurrentUser();
            var token = AuthStateService._getToken();
            if (token) {
              config.headers['Authorization'] = 'Basic' + user + ':' + token;
            }
            return config || $q.when(config);
          }
        };
      }];
  
      $httpProvider.interceptors.push(httpAuthInterceptor);
  }]);
  </code></pre>
  
  <p>So, when I call the service below, the return of service (data) is OK 3 times (OKOKOK).</p>
  
  <pre><code>.factory("connectAPI", ['$http', 'config', 'loginAPI', function($http, config, loginAPI){
    var _connect = function(callBack){
      var param = {
          user: loginAPI.getUser(),
          pass: loginAPI.getPass()
        };
  
      $http.get(config.baseUrl + 'connect/user/' + param.user + '/pass/' + param.pass)
        .success(function(data){
          callBack(data);
        })
        .error(function(data, status, headers, config){
          console.log(data, status, headers, config);
        });
    };
  
    return {
      connect: _connect
    };
  }])
  </code></pre>
  
  <p>My api method:</p>
  
  <pre><code>@Path("user/{user}/pass/{pass}")
  @GET
  @Produces({ MediaType.APPLICATION_JSON  + ";charset=utf-8"})
  public String getUserData(@PathParam("user") String user, @PathParam("pass") String pass) {
    if (user != "" &amp;&amp; pass != ""){
      //test
      return "OK"
    }
    return "NOK"
  }
  </code></pre>
  
  <p>I have checked it and the api method was calling 3 times. I don't know what is happening.</p>
  
  <p>When I comment the header authorization line, the api method is calling just 1 time. What is wrong?</p>
  
  <pre><code>.config(['$httpProvider', function($httpProvider) {
      var httpAuthInterceptor = [ 'AuthStateService', function(AuthStateService) {
        return {
          'request': function(config) {
            var user = AuthStateService.getCurrentUser();
            var token = AuthStateService._getToken();
            //if (token) {
            //  config.headers['Authorization'] = 'Basic' + user + ':' + token;
            //}
            return config || $q.when(config);
          }
        };
      }];
  
      $httpProvider.interceptors.push(httpAuthInterceptor);
  }]);
  </code></pre>