network/http_server/requests/root_page.c

/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#include "gos.h"
static const char webpage_body[] =
{
"<!DOCTYPE html>"
"<html>"
"<head>"
"<title>HTTP Server Example</title>"
"</head>"
"<body>"
"<h1>Dynamic Root Webpage</h1>"
"<p>Current time: %s</p>"
"</body>"
"</html>"
};
/*************************************************************************************************/
gos_result_t root_page_request(const gos_hs_request_t *request, const char *arg)
{
gos_result_t result;
char html_page[sizeof(webpage_body) + sizeof(gos_iso8601_str_t)];
const int len = sprintf(html_page, webpage_body, (const char*)&time_str);
if (GOS_FAILED(result, gos_hs_write_reply_header(request, "text/html", len, GOS_HS_RESPONSE_FLAG_NONE)))
{
}
else if (GOS_FAILED(result, gos_hs_write_data(request, html_page, len, true)))
{
}
return result;
}