First, the context of what I am doing. I am running an HttpServer that handles HttpRequests.
HttpServer.bind(ADDRESS, PORT).then((HttpServer server) { listenSubscription = server.listen(onRequest); }); void onRequest(HttpRequest request) { //handle request here }
I would like to add some entries to all of this, and because of the asynchronous nature, all this wants to add some identification markers to the requests (so I can match the received requests with the answers, example), The code inside onRequest() calls many other functions to do different things (handle GET and POST requests, etc.), so just generating an identifier at the top is a cumbersome decision, since I have to go through all these other function calls. However, I already went around the HttpRequest object, so I thought it would be nice to throw an id field into it, just like in Javascript, except that Dart does not work that way.
Thoughts then moved on to a subclass of the HttpRequest , but converting the HttpRequest object obtained by the onRequest() method seemed a lot more difficult and overhead than I needed.
So, I ask, is there any idiomatic way for Darth to attach some data to an existing object? If there is something idiomatic, then what is the simplest (both in code and at runtime), how can you come up with this?
source share