diff --git a/src/usb/lwip/rest.c b/src/usb/lwip/rest.c index 6f468f0..b146802 100644 --- a/src/usb/lwip/rest.c +++ b/src/usb/lwip/rest.c @@ -293,11 +293,21 @@ const char *rest_method_to_string(rest_http_method_t method) { } } -bool rest_content_type_is_json(const char *content_type) { +bool rest_supported_content_type(const char *content_type) { if (content_type == NULL) { return false; } - return strncasecmp(content_type, "application/json", 16) == 0; + const char *supported_types[] = { + "application/json", + "application/x-pem-file" + }; + printf("[rest] Checking content type: %s\n", content_type); + for (size_t i = 0; i < sizeof(supported_types) / sizeof(supported_types[0]); i++) { + if (strncasecmp(content_type, supported_types[i], strlen(supported_types[i])) == 0) { + return true; + } + } + return false; } #ifndef _MSC_VER diff --git a/src/usb/lwip/rest.h b/src/usb/lwip/rest.h index e85929e..96221d6 100644 --- a/src/usb/lwip/rest.h +++ b/src/usb/lwip/rest.h @@ -167,7 +167,7 @@ extern int rest_execute_route_handler(const rest_request_t *request, rest_route_ extern int rest_response_set_error(rest_response_t *response, int status_code, const char *message); const char *rest_status_text_from_code(uint16_t code); const char *rest_method_to_string(rest_http_method_t method); -bool rest_content_type_is_json(const char *content_type); +bool rest_supported_content_type(const char *content_type); const rest_route_t *rest_get_routes(size_t *count); diff --git a/src/usb/lwip/rest_server.c b/src/usb/lwip/rest_server.c index ac88fc4..6a5509c 100644 --- a/src/usb/lwip/rest_server.c +++ b/src/usb/lwip/rest_server.c @@ -754,8 +754,8 @@ void rest_handle_request(rest_conn_t *conn) { rest_debug_dump_payload("request-body", request->body, request->body_len); if (request->method == REST_HTTP_POST || request->method == REST_HTTP_PUT) { - if (!rest_content_type_is_json(request->content_type) && strncasecmp(request->content_type, "application/x-pem-file", 22) != 0) { - send_json_error(conn, 415, "content_type_must_be_application_json"); + if (!rest_supported_content_type(request->content_type)) { + send_json_error(conn, 415, "content_type_not_supported"); return; } }