Skip to content

htmlkit accessor in Request changes the global environment #186

@Frizlab

Description

@Frizlab

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions