Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Development/nmos/api_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cpprest/uri_schemes.h"
#include "cpprest/ws_utils.h"
#include "nmos/api_version.h"
#include "nmos/media_type.h"
#include "nmos/slog.h"
#include "nmos/type.h"
#include "nmos/version.h"
Expand Down Expand Up @@ -190,7 +191,7 @@ namespace nmos
const auto accept = req.headers().find(web::http::header_names::accept);
return req.headers().end() != accept
&& !boost::algorithm::contains(accept->second, mime_type)
&& boost::algorithm::contains(accept->second, U("text/html"));
&& boost::algorithm::contains(accept->second, nmos::media_types::text_html.name);
}

web::json::value make_html_response_a_tag(const web::uri& href, const web::json::value& value)
Expand Down Expand Up @@ -563,7 +564,7 @@ namespace nmos
if (web::http::details::is_mime_type_json(mime_type) && experimental::details::is_html_response_preferred(req, mime_type))
{
res.set_body(nmos::experimental::make_html_response_body(res, gate));
res.headers().set_content_type(U("text/html; charset=utf-8"));
res.headers().set_content_type(nmos::media_types::text_html.name + U("; charset=utf-8"));
}

slog::detail::logw<slog::log_statement, slog::base_gate>(gate, slog::severities::more_info, SLOG_FLF) << nmos::stash_categories({ nmos::categories::access }) << nmos::common_log_stash(req, res) << "Sending response after " << processing_dur << "ms";
Expand Down
19 changes: 14 additions & 5 deletions Development/nmos/connection_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "nmos/is04_versions.h"
#include "nmos/is05_versions.h"
#include "nmos/json_schema.h"
#include "nmos/media_type.h"
#include "nmos/model.h"
#include "nmos/sdp_utils.h"
#include "nmos/slog.h"
Expand Down Expand Up @@ -634,16 +635,22 @@ namespace nmos
{
slog::log<slog::severities::info>(gate, SLOG_FLF) << "Returning transport file for " << id_type;

const auto transportfile_type = nmos::fields::transportfile_type(transportfile);

// hmm, parsing of the Accept header could be much better and should take account of quality values
if (!accept.empty() && web::http::details::mime_types::application_json == web::http::details::get_mime_type(accept) && U("application/sdp") == nmos::fields::transportfile_type(transportfile))
const auto accept_type = web::http::details::get_mime_type(accept);
// allow application/json as well as the more precise application/sdp+json
const std::set<utility::string_t> sdp_json_types{ nmos::media_types::application_json.name, nmos::media_types::application_sdp_json.name };
if (nmos::media_types::application_sdp.name == transportfile_type && 0 != sdp_json_types.count(accept_type))
{
// Experimental extension - SDP as JSON
res.headers().set_content_type(accept_type);
set_reply(res, status_codes::OK, sdp::parse_session_description(utility::us2s(data.as_string())));
}
else
{
// This automatically performs conversion to UTF-8 if required (i.e. on Windows)
set_reply(res, status_codes::OK, data.as_string(), nmos::fields::transportfile_type(transportfile));
set_reply(res, status_codes::OK, data.as_string(), transportfile_type);
}

// "It is strongly recommended that the following caching headers are included via the /transportfile endpoint (or whatever this endpoint redirects to).
Expand Down Expand Up @@ -803,7 +810,7 @@ namespace nmos
// Validate and parse the specified transport file for the specified receiver
web::json::value parse_rtp_transport_file(const nmos::resource& receiver, const nmos::resource& connection_receiver, const utility::string_t& transport_file_type, const utility::string_t& transport_file_data, slog::base_gate& gate)
{
if (transport_file_type != U("application/sdp"))
if (transport_file_type != nmos::media_types::application_sdp.name)
{
throw std::runtime_error("unexpected type: " + utility::us2s(transport_file_type));
}
Expand Down Expand Up @@ -1185,12 +1192,14 @@ namespace nmos

// hmm, parsing of the Accept header could be much better and should take account of quality values
const auto accept = req.headers().find(web::http::header_names::accept);
if (req.headers().end() != accept && U("application/schema+json") == web::http::details::get_mime_type(accept->second))
const auto accept_or_empty = req.headers().end() != accept ? accept->second : utility::string_t{};
const auto accept_type = web::http::details::get_mime_type(accept_or_empty);
if (nmos::media_types::application_schema_json.name == accept_type)
{
// Experimental extension - constraints as JSON Schema

const nmos::transport transport_subclassification(nmos::fields::transport(matching_resource->data));
res.headers().set_content_type(U("application/schema+json"));
res.headers().set_content_type(accept_type);
set_reply(res, status_codes::OK, nmos::details::make_constraints_schema(resource->type, nmos::fields::endpoint_constraints(resource->data), nmos::transport_base(transport_subclassification)));
}
else
Expand Down
3 changes: 2 additions & 1 deletion Development/nmos/connection_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "nmos/api_utils.h" // for nmos::http_scheme
#include "nmos/is05_versions.h"
#include "nmos/is07_versions.h"
#include "nmos/media_type.h" // for nmos::media_types::application_sdp
#include "nmos/resource.h"

namespace nmos
Expand Down Expand Up @@ -171,7 +172,7 @@ namespace nmos

return value_of({
{ nmos::fields::transportfile_data, transportfile },
{ nmos::fields::transportfile_type, U("application/sdp") }
{ nmos::fields::transportfile_type, nmos::media_types::application_sdp.name }
});
}

Expand Down
11 changes: 11 additions & 0 deletions Development/nmos/media_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ namespace nmos

// See SMPTE ST 2022-8:2019
const media_type video_SMPTE2022_6{ U("video/SMPTE2022-6") };

// Additional media types for NMOS responses

const media_type application_sdp{ U("application/sdp") };

// experimental extension, to support HTML rendering of NMOS responses
const media_type text_html{ U("text/html") };

// experimental extension, to support JSON rendering in NMOS responses
const media_type application_schema_json{ U("application/schema+json") };
const media_type application_sdp_json{ U("application/sdp+json") };
}
}

Expand Down
7 changes: 4 additions & 3 deletions Development/nmos/node_api_target_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "nmos/client_utils.h"
#include "nmos/is05_versions.h"
#include "nmos/json_fields.h"
#include "nmos/media_type.h" // for nmos::media_types::application_sdp
#include "nmos/model.h"
#include "nmos/slog.h"

Expand Down Expand Up @@ -47,9 +48,9 @@ namespace nmos
{
slog::log<slog::severities::warning>(gate, SLOG_FLF) << "Missing Content-Type: should be application/sdp";
}
else if (U("application/sdp") != content_type)
else if (nmos::media_types::application_sdp.name != content_type)
{
throw web::http::http_exception(U("Incorrect Content-Type: ") + content_type + U(", should be application/sdp"));
throw web::http::http_exception(U("Incorrect Content-Type: ") + content_type + U(", should be ") + nmos::media_types::application_sdp.name);
}

return res.extract_string(true);
Expand All @@ -66,7 +67,7 @@ namespace nmos
})},
{ nmos::fields::transport_file, value_of({
{ nmos::fields::data, sdp },
{ nmos::fields::type, U("application/sdp") }
{ nmos::fields::type, nmos::media_types::application_sdp.name }
})}
});

Expand Down
5 changes: 3 additions & 2 deletions Development/nmos/schemas_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "nmos/api_utils.h"
#include "nmos/json_schema.h"
#include "nmos/log_manip.h"
#include "nmos/media_type.h" // for nmos::media_types::application_schema_json

namespace nmos
{
Expand Down Expand Up @@ -185,10 +186,10 @@ namespace nmos

if (schemas.end() != found)
{
res.headers().set_content_type(U("application/schema+json"));
res.headers().set_content_type(nmos::media_types::application_schema_json.name);

// experimental extension, to support human-readable HTML rendering of NMOS responses
if (experimental::details::is_html_response_preferred(req, U("application/schema+json")))
if (experimental::details::is_html_response_preferred(req, nmos::media_types::application_schema_json.name))
{
const auto base_uri = web::uri_builder().set_path(U("/schemas/") + repository + U("/") + tag + U("/")).to_uri();
set_reply(res, status_codes::OK, details::make_json_schema_html_response_body(base_uri, found->second));
Expand Down