network/http_server/requests/root_page.c

/*
* EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
* CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
* IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
* PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
* (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
*/
#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;
}