title: Can't specify headers in request in AngularJS
body: <p>I have 2 parts in my app - Angular frontend and rails server. And because it's different domains, requests doesn't work by default. There are a lot of staff about that, including stack, but it doesn't works for me.</p>
  
  <p>This is my method in angular controller:</p>
  
  <pre><code>$scope.test =-&gt;
    # transform = (data) -&gt;
    #   $.param data
  
    $http.post('http://localhost:3000/session/create', 'token=some',
      headers:
        'Access-Control-Allow-Origin': 'http://localhost:9000',
        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
        'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'
      # transformRequest: transform
    ).success (responseData) -&gt;
      console.log(responseData)
  </code></pre>
  
  <p>I commented transform data, there is no difference in server response.</p>
  
  <p>And I configured app (saw this in some post) like that:</p>
  
  <pre><code>.config ["$httpProvider", ($httpProvider) -&gt;
    $httpProvider.defaults.useXDomain = true
    delete $httpProvider.defaults.headers.common["X-Requested-With"]
  ]
  </code></pre>
  
  <p>I guess that makes request not ajax like (but i'm not sure).</p>
  
  <p>But there is no headers in my request. They all in some field <code>Access-Control-Request-Headers:access-control-allow-origin, accept, access-control-allow-headers, access-control-allow-methods, content-type</code>:</p>
  
  <pre><code>    Request URL:http://localhost:3000/session/create
      Request Method:OPTIONS
      Status Code:404 Not Found
  
      Request Headers
  
      Accept:*/*
      Accept-Encoding:gzip,deflate,sdch
      Accept-Language:en-US,en;q=0.8,ru;q=0.6
      Access-Control-Request-Headers:access-control-allow-origin, accept, access-control-allow-headers, access-control-allow-methods, content-type
      Access-Control-Request-Method:POST
      Connection:keep-alive
      DNT:1
      Host:localhost:3000
      Origin:http://localhost:9000
      Referer:http://localhost:9000/
      User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.8 Safari/537.36
  
      Response Headers
  
      Content-Length:12365
      Content-Type:text/html; charset=utf-8
      X-Request-Id:2cf4b37b-eb47-432a-ab30-b802b3e33218
      X-Runtime:0.030128
  </code></pre>
  
  <p>Chrome console:</p>
  
  <pre><code>OPTIONS http://localhost:3000/session/create 404 (Not Found) angular.js:6730
  OPTIONS http://localhost:3000/session/create No 'Access-Control-Allow-Origin' header is     present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. angular.js:6730
  XMLHttpRequest cannot load http://localhost:3000/session/create. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. localhost/:1
  </code></pre>
  
  <p>Other insignificant information:
  On the server:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    before_filter :allow_cross_domain_access
  
    protected
  
    def allow_cross_domain_access
      headers['Access-Control-Allow-Origin'] = '*'# http://localhost:9000
      headers['Access-Control-Allow-Headers'] = 'GET, POST, PUT, DELETE'
      headers['Access-Control-Allow-Methods'] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(',')
      headers['Access-Control-Max-Age'] = '1728000'
  
    end
  end
  </code></pre>
  
  <p>Routes is obvious <code>post "session/create"</code>. And session controller:</p>
  
  <pre><code>class SessionController &lt; ApplicationController
    respond_to :json, :html, :js
  
    def create
      respond_with "logged in"
      # render nothing: true
    end
  end
  </code></pre>
  
  <p>I use latest version of angular 1.2.0.rc-2. <a href="https://github.com/zishe/reader_frontend/blob/master/app/scripts/app.coffee" rel="noreferrer">this is my project on github</a></p>