0

I have small java application with rest api. It's deployed and available with url like http://1.1.1.1:8080/rest. Also I enabled CORS filter there and it works find.

But also I would like to configure access to my api with url like "http://myhost.com/". In this case CORS filter stop working.

Any ideas?


UPD1
Available headers:

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");


UPD2
Updated 'Access-Control-Allow-Headers':

        response.setHeader("Access-Control-Allow-Headers",
                    "x-requested-with, " +
                    "Content-Type, " +
                    "Host, " +
                    "User-Agent, " +
                    "Accept, " +
                    "Accept-Language, " +
                    "Accept-Encoding, " +
                    "Referer, " +
                    "Origin, " +
                    "Connection, " +
                    "Cache-Control");

Request:

GET /list HTTP/1.1
Host: myhost.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: */*
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://mysecondhost.com/test.html
Origin: http://mysecondhost.com
Connection: keep-alive
Cache-Control: max-age=0


UPD3
Looks like we have nginx there with the following headers configuration:

        add_header 'Access-Control-Allow-Methods' 'GET,POST,DELETE,OPTIONS';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Headers' 'WD-Since,WD-Start,WD-Direction,WD-Length,WD-Ids,Content-Type,WD-Client-Id';
        add_header 'Access-Control-Expose-Headers' 'WD-Total-Length,WD-Phone-Modal,WD-Client-Id,WD-Udid,WD-Need-More';
        proxy_cache off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8080/rest/;


Alex
  • 967
  • 4
  • 15
  • 38
  • Can you provide your CORS filter configuration ? Maybe you need to add more allowed headers. – Jul13nT Aug 15 '14 at 19:56
  • Look at the headers sent by your server and allow them like this `response.setHeader("Access-Control-Allow-Headers", "x-requested-with, X-Auth-Token, Content-Type, ...");` – Jul13nT Aug 15 '14 at 20:25
  • @Jul13nT No luck. See upd2. Also I attached original request. – Alex Aug 15 '14 at 20:45

1 Answers1

2

I spent a lot of time for reading another stackoverflow and serverfault posts... And I have found the solution.

Most helpful (for me) links: link1 link2 link3 link4

The solution is very simple: I removed 'add_header' from nginx configuration. After that I have CORS configuration in web application only.

Community
  • 1
  • 1
Alex
  • 967
  • 4
  • 15
  • 38