v0.1.3 - Implement https

This commit is contained in:
Your Name
2025-11-09 19:57:45 -04:00
parent e43dd5c64f
commit 30e4408b28
5 changed files with 18 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -44,19 +44,29 @@ int nip94_get_origin(char* out, size_t out_size) {
if (!out || out_size == 0) { if (!out || out_size == 0) {
return 0; return 0;
} }
// Check if request came over HTTPS (nginx sets HTTPS=on for SSL requests)
const char* https_env = getenv("HTTPS");
if (https_env && strcmp(https_env, "on") == 0) {
// HTTPS request - use HTTPS origin
strncpy(out, "https://localhost:9443", out_size - 1);
out[out_size - 1] = '\0';
return 1;
}
// HTTP request - check database config first, then use HTTP origin
sqlite3* db; sqlite3* db;
sqlite3_stmt* stmt; sqlite3_stmt* stmt;
int rc; int rc;
rc = sqlite3_open_v2(DB_PATH, &db, SQLITE_OPEN_READONLY, NULL); rc = sqlite3_open_v2(DB_PATH, &db, SQLITE_OPEN_READONLY, NULL);
if (rc) { if (rc) {
// Default on DB error // Default on DB error - use HTTP
strncpy(out, "http://localhost:9001", out_size - 1); strncpy(out, "http://localhost:9001", out_size - 1);
out[out_size - 1] = '\0'; out[out_size - 1] = '\0';
return 1; return 1;
} }
const char* sql = "SELECT value FROM server_config WHERE key = 'cdn_origin'"; const char* sql = "SELECT value FROM server_config WHERE key = 'cdn_origin'";
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
@@ -73,10 +83,10 @@ int nip94_get_origin(char* out, size_t out_size) {
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
sqlite3_close(db); sqlite3_close(db);
// Default fallback // Default fallback - HTTP
strncpy(out, "http://localhost:9001", out_size - 1); strncpy(out, "http://localhost:9001", out_size - 1);
out[out_size - 1] = '\0'; out[out_size - 1] = '\0';
return 1; return 1;

1
test_file.txt Normal file
View File

@@ -0,0 +1 @@
test file content