【问题标题】:Enabling cross-origin resource sharing on Apache Flume在 Apache Flume 上启用跨域资源共享
【发布时间】:2016-11-23 17:59:07
【问题描述】:

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

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

【问题讨论】:

    标签: cors flume flume-ng


    【解决方案1】:

    原来我不得不修改 Flume 的源代码。

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

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

    【讨论】:

      【解决方案2】:

      我在 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/;
      }
      

      希望这会有所帮助

      【讨论】:

        猜你喜欢
        • 2012-09-09
        • 2016-04-24
        • 2016-05-31
        • 2011-05-07
        • 2016-02-06
        • 2013-01-12
        • 2016-05-01
        相关资源
        最近更新 更多