Skip to content

Commit 1e3cc05

Browse files
committed
Enhance CORS handling for web browser in WhipServer and improve session ID retrieval
1 parent 68c33e9 commit 1e3cc05

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/projects/modules/whip/whip_server.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ std::shared_ptr<WhipInterceptor> WhipServer::CreateInterceptor()
299299
response->SetStatusCode(http::StatusCode::NotFound);
300300
return http::svr::NextHandler::DoNotCall;
301301
}
302-
302+
303303
if (_cors_manager.SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Post, http::Method::Patch, http::Method::Delete}) == false)
304304
{
305305
// CORS from default cors manager from virtual host
@@ -380,7 +380,11 @@ std::shared_ptr<WhipInterceptor> WhipServer::CreateInterceptor()
380380
}
381381

382382
// Set CORS header in response
383-
_cors_manager.SetupHttpCorsHeader(vhost_app_name, request, response);
383+
_cors_manager.SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Post});
384+
385+
// Access-Control-Expose-Headers header allows a server
386+
// to indicate which response headers should be made available to scripts running in the browser in response to a cross-origin request.
387+
response->AddHeader("Access-Control-Expose-Headers", "Location, Link, ETag");
384388

385389
// Set SDP
386390
response->SetHeader("Content-Type", "application/sdp");
@@ -511,12 +515,12 @@ std::shared_ptr<WhipInterceptor> WhipServer::CreateInterceptor()
511515
//TODO(way) : If url is changed by Webhooks, we use the changed url in PATCH request like delete request.
512516

513517
// Set CORS header in response
514-
_cors_manager.SetupHttpCorsHeader(vhost_app_name, request, response);
518+
_cors_manager.SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Patch});
515519

516-
auto session_id = request_url->GetQueryValue("session");
520+
auto session_id = request_url->File();
517521
if (session_id.IsEmpty())
518522
{
519-
logte("Could not get session id from query string");
523+
logte("Could not get session id from url");
520524
response->SetStatusCode(http::StatusCode::BadRequest);
521525
return http::svr::NextHandler::DoNotCall;
522526
}

0 commit comments

Comments
 (0)