Skip to content

Commit

Permalink
Support HEAD method to LLHLS, HLS, API pubs
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Oct 25, 2024
1 parent f4b3713 commit 80018c8
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/projects/modules/http/server/http_default_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ namespace http

if (error == nullptr)
{
// if mehotd == GET, set HEAD automatically
if (HTTP_CHECK_METHOD(method, Method::Get))
{
method |= Method::Head;
}

_request_handler_list.push_back((RequestInfo) {
#if DEBUG
.pattern_string = whole_pattern,
Expand Down
2 changes: 2 additions & 0 deletions src/projects/modules/http/server/http_exchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ namespace http
return InterceptorResult::Error;
}

GetResponse()->SetMethod(GetRequest()->GetMethod());

return interceptor->OnRequestCompleted(GetSharedPtr());
}

Expand Down
16 changes: 16 additions & 0 deletions src/projects/modules/http/server/http_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ namespace http
return _tls_data;
}

void HttpResponse::SetMethod(Method method)
{
_method = method;
}

Method HttpResponse::GetMethod() const
{
return _method;
}

StatusCode HttpResponse::GetStatusCode() const
{
return _status_code;
Expand Down Expand Up @@ -244,6 +254,12 @@ namespace http
}
}

if (GetMethod() == Method::Head)
{
_sent_size += sent_size;
return sent_size;
}

auto sent_data_size = SendPayload();
if (sent_data_size < 0)
{
Expand Down
5 changes: 5 additions & 0 deletions src/projects/modules/http/server/http_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace http
// Get Reason
ov::String GetReason() const;

void SetMethod(Method method);
Method GetMethod() const;

// reason = default
void SetStatusCode(StatusCode status_code);
// custom reason
Expand Down Expand Up @@ -123,6 +126,8 @@ namespace http
// Responsed time
std::chrono::system_clock::time_point _response_time;
uint32_t _sent_size = 0;

Method _method = Method::Unknown;
};
} // namespace svr
} // namespace http
2 changes: 1 addition & 1 deletion src/projects/publishers/hls/hls_http_interceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TsHttpInterceptor : public http::svr::DefaultInterceptor
auto parsed_uri = request->GetParsedUri();
auto file = parsed_uri->File().LowerCaseString();

if (request->GetMethod() == http::Method::Get || request->GetMethod() == http::Method::Options)
if (request->GetMethod() == http::Method::Get || request->GetMethod() == http::Method::Head || request->GetMethod() == http::Method::Options)
{
// ts:*.m3u8 is the master playlist for this HLS Publisher(HLSv3)
if (file.HasPrefix("ts:") && file.HasSuffix(".m3u8"))
Expand Down
4 changes: 2 additions & 2 deletions src/projects/publishers/hls/hls_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ std::shared_ptr<TsHttpInterceptor> HlsPublisher::CreateInterceptor()
auto application = std::static_pointer_cast<HlsApplication>(GetApplicationByName(vhost_app_name));
if (application != nullptr)
{
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Get});
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Get, http::Method::Head});
}
else
{
Expand Down Expand Up @@ -510,7 +510,7 @@ std::shared_ptr<TsHttpInterceptor> HlsPublisher::CreateInterceptor()
session->UpdateLastRequest(connection->GetId());

// Cors Setting
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response);
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Get, http::Method::Head});
stream->SendMessage(session, std::make_any<std::shared_ptr<http::svr::HttpExchange>>(exchange));

return http::svr::NextHandler::DoNotCallAndDoNotResponse;
Expand Down
2 changes: 1 addition & 1 deletion src/projects/publishers/llhls/llhls_http_interceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LLHlsHttpInterceptor : public http::svr::DefaultInterceptor
auto parsed_uri = request->GetParsedUri();
auto file = parsed_uri->File().LowerCaseString();

if (request->GetMethod() == http::Method::Get || request->GetMethod() == http::Method::Options)
if (request->GetMethod() == http::Method::Get || request->GetMethod() == http::Method::Head || request->GetMethod() == http::Method::Options)
{
// ts:*.m3u8 is the master playlist for this HLSv3 Publisher(HLSv3)
if (file.HasPrefix("ts:") && file.HasSuffix(".m3u8"))
Expand Down
4 changes: 2 additions & 2 deletions src/projects/publishers/llhls/llhls_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ std::shared_ptr<LLHlsHttpInterceptor> LLHlsPublisher::CreateInterceptor()
auto application = std::static_pointer_cast<LLHlsApplication>(GetApplicationByName(vhost_app_name));
if (application != nullptr)
{
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Get});
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Get, http::Method::Head});
}
else
{
Expand Down Expand Up @@ -505,7 +505,7 @@ std::shared_ptr<LLHlsHttpInterceptor> LLHlsPublisher::CreateInterceptor()
session->UpdateLastRequest(connection->GetId());

// Cors Setting
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response);
application->GetCorsManager().SetupHttpCorsHeader(vhost_app_name, request, response, {http::Method::Options, http::Method::Get, http::Method::Head});
stream->SendMessage(session, std::make_any<std::shared_ptr<http::svr::HttpExchange>>(exchange));

return http::svr::NextHandler::DoNotCallAndDoNotResponse;
Expand Down

0 comments on commit 80018c8

Please sign in to comment.