在Apache Flume上启用跨源资源共享

时间:2016-11-23 17:59:07

标签: cors flume flume-ng

我正在开发一个基本上通过端口8080连接到Flume服务器的网页。每次客户端发送新的请求时,它都会抛出403 Forbidden错误,因为HTTP源不知道如何处理OPTIONS请求。

Apache Flume的文档中没有具体提及如何启用CORS。

2 个答案:

答案 0 :(得分:1)

我在flume前面使用nginx代理来设置CORS标头,而不是对flume进行设置。

这是我的代理定义:

server {
#proxy server for flume
listen   15140; ## listen for ipv4; this line is default and implied
location / {
    if ($request_method = 'OPTIONS') {
                add_header Access-Control-Allow-Origin $http_origin always;
                add_header Access-Control-Allow-Credentials true always;
                add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE,OPTIONS' always;
                add_header Access-Control-Allow-Headers 'Authorization,X-Requested-With,Content-Type,Origin,Accept,token' always;
                add_header Access-Control-Max-Age 3600;
                add_header Content-Length 0;
                return 200;
    }

    add_header Access-Control-Allow-Origin $http_origin always;
    add_header Access-Control-Allow-Credentials true always;
    add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE,OPTIONS' always;
    add_header Access-Control-Allow-Headers 'Authorization,X-Requested-With,Content-Type,Origin,Accept,token' always;

    proxy_pass http://localhost:5140/;
}

希望这会有所帮助

答案 1 :(得分:0)

事实证明我必须修改Flume的源代码。

在文件HTTPSource(私有类 FlumeHTTPServlet )中,添加以下方法:

@Override
public void doOptions(HttpServletRequest request, HttpServletResponse response)
throws IOException
{
    response.addHeader("Access-Control-Allow-Origin", "*");
}
相关问题