-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
Description
AFAICT when accessing htmlkit from a Request, if there is an accept-language
header, the global htmlkit.configuration.environment
is modified.
This is bad for two reasons:
- If two requests are served at the same time and do not have the same language, the resulting language for both requests will be randomly one or the other (or part of a response in a language and the rest in another);
- Setting the environment is done in a non-concurrent-safe manner, resulting in potential crashes due to incorrect memory access (I got a few while developing (low number of requests), the code is definitely dangerous).
Instead of re-inventing the wheel, I’d argue for using swift-service-context instead, which is concurrent-safe and can be modified per Task (would work if Vapor is already using structured concurrency for serving requests, which I think it does, but I’m not 100% sure of that).
Otherwise using the current service system Vapor has setup would also be good.