Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

Make Rocket an implementation detail of Nemesis #97

Merged
merged 29 commits into from
Jun 6, 2019
Merged

Conversation

lopopolo
Copy link
Member

@lopopolo lopopolo commented Jun 5, 2019

This PR builds upon what I learned in rwf2/Rocket#1019 and pulls the Rocket dependency inside nemesis crate.

Rocket is an implementation detail of using nemesis to serve a Rack app. This PR creates an interface on top of Rocket to abstract over the server implementation if I want to later switch to e.g. a Hyper backend.

The public interface to nemesis is a Builder struct that is used to configure routes for serving static assets and mounting Rack apps at a base path:

  • Static assets are stored in Rocket managed state and served directly, using extension based ContentType detection.
  • Rack apps are managed by two new constructs:
    • RackApp wraps a Value and Mrb where the Value is a Ruby object that responds to #call(env). RackApp implements ValueLike and exposes a typed interface around #call(env) that returns a nemesis Response.
    • Mount contains the information necessary to serve a RackApp at a prefix. It contains the base path mount point, a Fn that returns an interpreter and a Fn that returns a RackApp given an interpreter.

To handle a generic Rack application that responds to all paths and all HTTP methods, I introduce a RackHandler custom Rocket handler that generates all of the routes. The RackHandler contains a cloneable reference to the Mount.

Currently, nemesis only supports the shared nothing exec mode where there is a new single use interpreter created per request. In a followup PR I would like to add support for per-worker-per-app interpreters.

This PR significantly refactors the error handling in nemesis crate. I found I was repeating myself a lot by introducing new Error types in each module and wrapping them and adding From implementations. Instead, there is a global Error type in the nemesis crate root that implements all errors for all components in nemesis.

foolsgold crate is now fully implemented in terms of nemesis and has no direct dependency on Rocket.

Begin to hide Rocket implementation from consumers of nemesis. nemesis::server::Request
provides a default implementation to generate Rack environment hashes and requires
implementations to supply the Rack values.

Rocket is an implementation detail of nemesis and the backend may change in the future,
e.g. to Hyper.
Kill all of the dead code in foolsgold. This commit drops support for a shared interpreter.
The handler matches all paths at the mount point and responds to all
HTTP methods.
The server implementation lives entirely in nemesis now
The only exported bits are Error, Builder, Mount.
foolsgold/src/main.rs Outdated Show resolved Hide resolved
nemesis/src/server/mod.rs Outdated Show resolved Hide resolved
nemesis/src/server/mod.rs Outdated Show resolved Hide resolved
nemesis/src/server/rocket/mod.rs Outdated Show resolved Hide resolved
nemesis/src/server/rocket/request.rs Outdated Show resolved Hide resolved
nemesis/src/server/rocket/routes.rs Show resolved Hide resolved
@lopopolo lopopolo merged commit ba4cb7d into master Jun 6, 2019
@lopopolo lopopolo deleted the rocket-env branch June 6, 2019 01:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant