Skip to content

Commit ec9797d

Browse files
authored
Merge pull request #227 from MDA2AV/reso229
h1 static results
2 parents 10ab2e2 + 7488525 commit ec9797d

273 files changed

Lines changed: 39246 additions & 53939 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frameworks/actix/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"compression",
1717
"mixed",
1818
"async-db",
19+
"static",
1920
"baseline-h2",
2021
"static-h2"
2122
]

frameworks/bun/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"noisy",
1717
"mixed",
1818
"async-db",
19+
"static",
1920
"baseline-h2",
2021
"static-h2"
2122
]

frameworks/chi/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"compression",
1616
"upload",
1717
"mixed",
18-
"async-db"
18+
"async-db",
19+
"static"
1920
]
2021
}

frameworks/deno/main.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import { Database } from "jsr:@db/sqlite@0.12";
22
import { gzipSync } from "node:zlib";
33

4+
const MIME_TYPES: Record<string, string> = {
5+
".css": "text/css", ".js": "application/javascript", ".html": "text/html",
6+
".woff2": "font/woff2", ".svg": "image/svg+xml", ".webp": "image/webp", ".json": "application/json",
7+
};
8+
9+
// Pre-load static files
10+
const staticFiles: Record<string, { data: Uint8Array; contentType: string }> = {};
11+
try {
12+
for (const entry of Deno.readDirSync("/data/static")) {
13+
if (!entry.isFile) continue;
14+
const data = Deno.readFileSync(`/data/static/${entry.name}`);
15+
const ext = entry.name.slice(entry.name.lastIndexOf("."));
16+
staticFiles[entry.name] = { data, contentType: MIME_TYPES[ext] || "application/octet-stream" };
17+
}
18+
} catch { /* static dir not available */ }
19+
420
const datasetPath = Deno.env.get("DATASET_PATH") || "/data/dataset.json";
521
let datasetItems: any[] | undefined;
622

@@ -167,6 +183,17 @@ export default {
167183
return new Response(String(size), { headers: PLAIN });
168184
}
169185

186+
if (path.startsWith("/static/")) {
187+
const filename = path.slice(8);
188+
const sf = staticFiles[filename];
189+
if (sf) {
190+
return new Response(sf.data, {
191+
headers: { "content-type": sf.contentType, "content-length": String(sf.data.length), "server": "deno" },
192+
});
193+
}
194+
return new Response("Not found", { status: 404 });
195+
}
196+
170197
// /baseline11
171198
let sum = sumQuery(url, pathStart);
172199
if (req.method === "POST") {

frameworks/deno/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"upload",
1616
"compression",
1717
"mixed",
18-
"async-db"
18+
"async-db",
19+
"static"
1920
]
2021
}

frameworks/django/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"upload",
1616
"compression",
1717
"mixed",
18-
"async-db"
18+
"async-db",
19+
"static"
1920
]
2021
}

frameworks/django/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
django==5.2
22
gunicorn==23.0.0
3-
psycopg[binary]==3.2.4
3+
psycopg[binary]==3.2.6
44
psycopg_pool==3.2.6

frameworks/django/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.urls import path
2-
from views import pipeline, baseline11, baseline2, json_endpoint, compression_endpoint, db_endpoint, async_db_endpoint, upload_endpoint
2+
from views import pipeline, baseline11, baseline2, json_endpoint, compression_endpoint, db_endpoint, async_db_endpoint, upload_endpoint, static_file
33

44
urlpatterns = [
55
path('pipeline', pipeline),
@@ -10,4 +10,5 @@
1010
path('db', db_endpoint),
1111
path('async-db', async_db_endpoint),
1212
path('upload', upload_endpoint),
13+
path('static/<str:filename>', static_file),
1314
]

frameworks/django/views.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
from django.http import HttpResponse, HttpResponseNotAllowed
99
from django.views.decorators.http import require_http_methods, require_GET
1010

11+
# ── MIME types ────────────────────────────────────────────────────────
12+
MIME_TYPES = {
13+
'.css': 'text/css', '.js': 'application/javascript', '.html': 'text/html',
14+
'.woff2': 'font/woff2', '.svg': 'image/svg+xml', '.webp': 'image/webp', '.json': 'application/json',
15+
}
16+
17+
# ── Pre-load static files ────────────────────────────────────────────
18+
static_files = {}
19+
try:
20+
for name in os.listdir('/data/static'):
21+
filepath = os.path.join('/data/static', name)
22+
if os.path.isfile(filepath):
23+
with open(filepath, 'rb') as f:
24+
data = f.read()
25+
ext = os.path.splitext(name)[1]
26+
ct = MIME_TYPES.get(ext, 'application/octet-stream')
27+
static_files[name] = (data, ct)
28+
except Exception:
29+
pass
30+
1131
# Load raw dataset for per-request processing
1232
dataset_items = None
1333
dataset_path = os.environ.get('DATASET_PATH', '/data/dataset.json')
@@ -212,3 +232,16 @@ def upload_endpoint(request):
212232
resp = HttpResponse(str(total), content_type='text/plain')
213233
resp['Server'] = 'django'
214234
return resp
235+
236+
237+
@require_GET
238+
def static_file(request, filename):
239+
entry = static_files.get(filename)
240+
if entry is None:
241+
resp = HttpResponse(b'Not Found', status=404, content_type='text/plain')
242+
resp['Server'] = 'django'
243+
return resp
244+
data, ct = entry
245+
resp = HttpResponse(data, content_type=ct)
246+
resp['Server'] = 'django'
247+
return resp

frameworks/drogon/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class BenchmarkCtrl : public drogon::HttpController<BenchmarkCtrl>
400400
if (it != static_files.end()) {
401401
auto resp = HttpResponse::newHttpResponse();
402402
resp->setBody(it->second.data);
403-
resp->addHeader("Content-Type", it->second.content_type);
403+
resp->setContentTypeString(it->second.content_type);
404404
callback(resp);
405405
} else {
406406
auto resp = HttpResponse::newHttpResponse();

0 commit comments

Comments
 (0)