Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frameworks/D/photon-http/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
],
"copyright": "Copyright © 2025, Dmitry Olshansky",
"dependencies": {
"asdf": "~>0.7.17",
"mir-ion": "~>2.3.4",
"xbuf" : "~>0.2.1",
"photon": "~>0.18.5",
"photon-http": "~>0.6.0"
"photon-http": "~>0.6.8"
},
"description": "Benchmark of photon-http",
"license": "BSL-1.0",
Expand Down
19 changes: 12 additions & 7 deletions frameworks/D/photon-http/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import std.stdio;
import std.socket;
import std.array;

import asdf.serialization;
import mir.ser;
import mir.ser.json;

import std.range.primitives;

import glow.xbuf;

import photon, photon.http;

Expand All @@ -14,21 +19,21 @@ struct Message
class BenchmarkProcessor : HttpProcessor {
HttpHeader[] plainText = [HttpHeader("Content-Type", "text/plain; charset=utf-8")];
HttpHeader[] json = [HttpHeader("Content-Type", "application/json")];
Appender!(char[]) jsonBuf;
Buffer!char jsonBuf;
this(Socket sock) {
super(sock);
jsonBuf = appender!(char[]);
jsonBuf = Buffer!char(256);
}

override void handle(HttpRequest req) {
if (req.uri == "/plaintext") {
respondWith("Hello, world!", 200, plainText);
respondWith("Hello, world!", HttpStatus.OK, plainText);
} else if(req.uri == "/json") {
jsonBuf.clear();
Message("Hello, World!").serializeToJsonPretty!""(jsonBuf);
respondWith(jsonBuf.data, 200, json);
serializeJsonPretty!""(jsonBuf, Message("Hello, World!"));
respondWith(jsonBuf.data, HttpStatus.OK, json);
} else {
respondWith("Not found", 404, plainText);
respondWith("Not found", HttpStatus.NotFound, plainText);
}
}
}
Expand Down
Loading