.well-known => C.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4837 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2024-02-10 16:10:58 +00:00
parent 5a978bb30d
commit 51a327c52d
2 changed files with 20 additions and 24 deletions

View File

@ -556,17 +556,6 @@ function startsWithBytes(data, bytes) {
}
}
async function wellKnownHandler(request, response, path) {
let data = await File.readFile("data/global/.well-known/" + path);
if (data) {
response.writeHead(200, {"Content-Type": "text/plain", "Content-Length": data.length});
response.end(data);
} else {
response.writeHead(404, {"Content-Type": "text/plain", "Content-Length": "File not found".length});
response.end("File not found");
}
}
function guessTypeFromName(path) {
let extension = path.split('.').pop();
return k_mime_types[extension];
@ -940,8 +929,6 @@ loadSettings().then(function() {
return blobHandler(request, response, match[1], match[2]);
} else if (match = /^(.*)(\/(?:save|delete)?)$/.exec(request.uri)) {
return blobHandler(request, response, match[1], match[2]);
} else if ((match = /^\/.well-known\/(.*)/.exec(request.uri)) && request.uri.indexOf("..") == -1) {
return wellKnownHandler(request, response, match[1]);
} else {
let data = "File not found.";
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": data.length.toString()});

View File

@ -2,7 +2,6 @@
#include "file.js.h"
#include "http.h"
#include "log.h"
#include "mem.h"
#include "task.h"
#include "tlscontext.js.h"
@ -581,7 +580,6 @@ static void _httpd_endpoint_static_read(tf_task_t* task, const char* path, int r
}
else
{
tf_printf("404 %s\n", path);
const char* k_payload = tf_http_status_text(404);
tf_http_respond(request, 404, NULL, 0, k_payload, strlen(k_payload));
}
@ -593,6 +591,14 @@ static void _httpd_endpoint_static_stat(tf_task_t* task, const char* path, int r
{
tf_http_request_t* request = user_data;
const char* match = tf_http_request_get_header(request, "if-none-match");
if (result != 0)
{
const char* k_payload = tf_http_status_text(404);
tf_http_respond(request, 404, NULL, 0, k_payload, strlen(k_payload));
tf_http_request_unref(request);
}
else
{
char etag[512];
snprintf(etag, sizeof(etag), "\"%f_%zd\"", _time_spec_to_double(&stat->st_mtim), (size_t)stat->st_size);
if (match && strcmp(match, etag) == 0)
@ -609,6 +615,7 @@ static void _httpd_endpoint_static_stat(tf_task_t* task, const char* path, int r
tf_file_read(task, path, _httpd_endpoint_static_read, file);
}
}
}
static void _httpd_endpoint_static(tf_http_request_t* request)
{
@ -634,6 +641,7 @@ static void _httpd_endpoint_static(tf_http_request_t* request)
{ "/lit/", "deps/lit/" },
{ "/codemirror/", "deps/codemirror/" },
{ "/speedscope/", "deps/speedscope/" },
{ "/.well-known/", "data/global/.well-known/" },
};
bool is_core = false;
@ -748,6 +756,7 @@ void tf_httpd_register(JSContext* context)
tf_http_add_handler(http, "/lit/", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/speedscope/", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/static/", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/.well-known/", _httpd_endpoint_static, NULL, task);
tf_http_add_handler(http, "/robots.txt", _httpd_endpoint_robots_txt, NULL, NULL);
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, NULL, task);