如何在oat++ hls服务器的响应头中添加cors

问题描述 投票:0回答:2
auto response = controller->createResponse(Status::CODE_200, controller->livePlaylist->generateForTime(time, 5)->toString());
      response->putHeader("Accept-Ranges", "bytes");
      //response->putHeader(allow_origin = "*");
      response->putHeader(Header::CONNECTION, Header::Value::CONNECTION_KEEP_ALIVE);
      response->putHeader(Header::CONTENT_TYPE, "application/x-mpegURL");
      response->putHeader(Header::CORS_METHODS,"GET, POST, PUT, OPTIONS, DELETE");
      response->putHeader(Header::CORS_ORIGIN, "*");
      response->putHeader(Header::CORS_HEADERS, "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range");
      response->putHeader(Header::CORS_MAX_AGE, "1728000");
      return _return(response);

这是异步端点的响应标头。

这是使用 oat++ 框架在 hls 流的响应标头中添加 cor 的正确方法吗?

oat++框架中添加cors的正确方法是什么?

c++ http-live-streaming oat++
2个回答
1
投票

Oat++ 具有处理 CORS 的内置功能。 只需将这些请求和响应拦截器添加到您的

AsyncHttpConnectionHandler

#include "oatpp/web/server/interceptor/AllowCorsGlobal.hpp"

...

  OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {

    OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component

    auto connectionHandler = oatpp::web::server::AsyncHttpConnectionHandler::createShared(router);

    /* Add CORS-enabling interceptors */
    connectionHandler->addRequestInterceptor(std::make_shared<oatpp::web::server::interceptor::AllowOptionsGlobal>());
    connectionHandler->addResponseInterceptor(std::make_shared<oatpp::web::server::interceptor::AllowCorsGlobal>());

    return connectionHandler;

  }());

0
投票

添加 CORS 现在更加容易。在您的控制器中,您必须在 ENDPOINT 定义之前添加。

ADD_CORS(getuptime)

仅此而已。

© www.soinside.com 2019 - 2024. All rights reserved.