July 17, 2018 [Fwd: [accu-general] Code Critique 112] | ||||
---|---|---|---|---|
| ||||
Attachments:
| Hi, Hopefully, people are preparing their submissions for this CVu Code Critique. I am writing one as we speak, but as I know absolutely SFA about Vibe.d I am sure it will be as crap as the code below. ACCU members would I suspect like to have some constructive material on using D for Web backends. Many of them know and use Go and Python. -------- Forwarded Message -------- > Code Critique 112 > > Hello all, > Below is the code for Code Critique number 112 > > As usual, please don't reply to the list with your entry but email scc@accu.org for collation. > > Regards, > Steve. > ------------------------------------------------------------------- > ----- > (Submissions to scc@accu.org by August 1st) > > Further to articles introducing D, I am attempting to use the > event-driven Vibe.d server library, which I understand to be like a > native version of Python's Tornado and potentially a “killer app” of > D > as I haven't seen any other mature event-driven server library in a > compiled language. > > I would like to build a back-end server that performs some processing > on > the body of the HTTP request it receives. To begin with, I would > like > it to simply echo the request body back to the client. > > My code works but there are three problems: (1) when I issue a POST > request with lynx, 3 spaces are added to the start of the response > text, > (2) I cannot test with nc because it just says 404 and doesn't log > anything, and (3) I'm worried that reading and writing just one byte > at > a time is inefficient, but I can't see how else to do it: I raised a > "more documentation needed" bug at > https://github.com/vibe-d/vibe.d/issues/2139 but at the time of > writing > nobody has replied (should I have used a different forum?) > > --- code --- > import vibe.d; > void main() { > auto settings = new HTTPServerSettings; > settings.port = 8080; > listenHTTP(settings, (req, res) { > ubyte[1] s; > while(!req.bodyReader.empty()) { > req.bodyReader.read(s); > res.bodyWriter.write(s); > } > }); > runApplication(); > } > > _______________________________________________ > accu-general mailing list > accu-general@accu.org > https://lists.accu.org/mailman/listinfo/accu-general -- Russel. =========================================== Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk |
Copyright © 1999-2021 by the D Language Foundation