Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Revision 141:25047f31dbab, committed 2019-04-27
- Comitter:
- andrewboyson
- Date:
- Sat Apr 27 09:24:44 2019 +0000
- Parent:
- 140:9000ea70b220
- Child:
- 142:a8c0890a58d1
- Commit message:
- Moved http status commands into this library
Changed in this revision
--- a/tcp/http/http.h Wed Apr 10 10:07:06 2019 +0000 +++ b/tcp/http/http.h Sat Apr 27 09:24:44 2019 +0000 @@ -18,6 +18,14 @@ extern void HttpAddInt64AsHex (int64_t value); extern void HttpAddTm (struct tm* ptm); +extern void HttpOk(const char* contentType, const char* cacheControl, const char* lastModifiedDate, const char* lastModifiedTime); +extern char* HttpOkCookieName; +extern char* HttpOkCookieValue; +extern int HttpOkCookieMaxAge; + +extern void HttpNotFound (void); +extern void HttpNotModified (void); + extern int HttpRequestRead (char *p, int len, char** ppMethod, char** ppPath, char** ppQuery, char** ppLastModified, char** ppCookies, int* pContentLength); extern char* HttpCookiesSplit (char* pCookies, char** ppName, char** ppValue);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp/http/status/http-not-found.c Sat Apr 27 09:24:44 2019 +0000
@@ -0,0 +1,7 @@
+#include "http.h"
+
+void HttpNotFound()
+{
+ HttpAddText("HTTP/1.1 404 Not Found\r\n"
+ "\r\n");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp/http/status/http-not-modified.c Sat Apr 27 09:24:44 2019 +0000
@@ -0,0 +1,12 @@
+#include "http.h"
+
+void HttpNotModified()
+{
+ HttpAddText("HTTP/1.1 304 Not Modified\r\n"
+ "Date: ");
+ char pDate[HTTP_DATE_LENGTH];
+ HttpDateFromNow(pDate);
+ HttpAddText(pDate);
+ HttpAddText("\r\n"
+ "\r\n");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp/http/status/http-ok.c Sat Apr 27 09:24:44 2019 +0000
@@ -0,0 +1,38 @@
+#include "log.h"
+#include "http.h"
+
+char* HttpOkCookieName;
+char* HttpOkCookieValue;
+int HttpOkCookieMaxAge = -1; //-1 = none, 0 = clear, +ve values = number of seconds
+
+void HttpOk(const char* contentType, const char* cacheControl, const char* lastModifiedDate, const char* lastModifiedTime)
+{
+ char pDate[HTTP_DATE_LENGTH];
+
+ if (!contentType) LogTimeF("HtmlOk - missing Content-Type info\r\n");
+ if (!cacheControl) LogTimeF("HtmlOk - missing Cache-Control info\r\n");
+
+ HttpAddF("HTTP/1.1 200 OK\r\n"
+ "Connection: close\r\n"
+ "Content-Type: %s\r\n", contentType);
+
+ HttpAddF("Cache-Control: %s\r\n", cacheControl);
+
+ HttpDateFromNow(pDate);
+ HttpAddF("Date: %s\r\n", pDate);
+
+ if (lastModifiedDate)
+ {
+ HttpDateFromDateTime(lastModifiedDate, lastModifiedTime, pDate);
+ HttpAddF("Last-Modified: %s\r\n", pDate);
+ }
+
+ if (HttpOkCookieName && HttpOkCookieValue)
+ {
+ HttpAddF("Set-Cookie: %s=%s", HttpOkCookieName, HttpOkCookieValue );
+ if (HttpOkCookieMaxAge >= 0) HttpAddF("; Max-Age=%d", HttpOkCookieMaxAge);
+ HttpAddText("\r\n");
+ }
+
+ HttpAddText("\r\n");
+}