Skip to content

Commit 8eb2a78

Browse files
DmitryOlshanskyDmitry Olshansky
andauthored
Switch JSON library for photon-http (#10190)
* Use Mir Ion for JSON and use buffer from xbuf * Use constants not magic numbers --------- Co-authored-by: Dmitry Olshansky <[email protected]>
1 parent 78fe686 commit 8eb2a78

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

frameworks/D/photon-http/dub.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
],
55
"copyright": "Copyright © 2025, Dmitry Olshansky",
66
"dependencies": {
7-
"asdf": "~>0.7.17",
7+
"mir-ion": "~>2.3.4",
8+
"xbuf" : "~>0.2.1",
89
"photon": "~>0.18.5",
9-
"photon-http": "~>0.6.0"
10+
"photon-http": "~>0.6.8"
1011
},
1112
"description": "Benchmark of photon-http",
1213
"license": "BSL-1.0",

frameworks/D/photon-http/source/app.d

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import std.stdio;
22
import std.socket;
33
import std.array;
44

5-
import asdf.serialization;
5+
import mir.ser;
6+
import mir.ser.json;
7+
8+
import std.range.primitives;
9+
10+
import glow.xbuf;
611

712
import photon, photon.http;
813

@@ -14,21 +19,21 @@ struct Message
1419
class BenchmarkProcessor : HttpProcessor {
1520
HttpHeader[] plainText = [HttpHeader("Content-Type", "text/plain; charset=utf-8")];
1621
HttpHeader[] json = [HttpHeader("Content-Type", "application/json")];
17-
Appender!(char[]) jsonBuf;
22+
Buffer!char jsonBuf;
1823
this(Socket sock) {
1924
super(sock);
20-
jsonBuf = appender!(char[]);
25+
jsonBuf = Buffer!char(256);
2126
}
2227

2328
override void handle(HttpRequest req) {
2429
if (req.uri == "/plaintext") {
25-
respondWith("Hello, world!", 200, plainText);
30+
respondWith("Hello, world!", HttpStatus.OK, plainText);
2631
} else if(req.uri == "/json") {
2732
jsonBuf.clear();
28-
Message("Hello, World!").serializeToJsonPretty!""(jsonBuf);
29-
respondWith(jsonBuf.data, 200, json);
33+
serializeJsonPretty!""(jsonBuf, Message("Hello, World!"));
34+
respondWith(jsonBuf.data, HttpStatus.OK, json);
3035
} else {
31-
respondWith("Not found", 404, plainText);
36+
respondWith("Not found", HttpStatus.NotFound, plainText);
3237
}
3338
}
3439
}

0 commit comments

Comments
 (0)