class Rewriter implements Wrapper {

	@Override public Handler wrap(final Handler handler) {

		if ( handler == null ) {
			throw new NullPointerException("null handler");
		}

		return request -> {

			final String external=request.base();
			final String internal=base;

			final boolean identity=external.isEmpty() || internal.isEmpty() || external.equals(internal);

			return identity ? handler.handle(request) : request
					.map(_request -> rewrite(_request, new Engine(external, internal)))
					.map(handler::handle)
					.map(_response -> rewrite(request, _response, new Engine(internal, external)));
		};
	}

	public  Rewriter(final String base);

}