com.jetdrone.vertx.yoke.middleware.ResponseHeaders Maven / Gradle / Ivy
package com.jetdrone.vertx.yoke.middleware;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.jetbrains.annotations.NotNull;
import org.vertx.java.core.Handler;
import com.jetdrone.vertx.yoke.Middleware;
/**
*
* A simple {@link Middleware} that allows adding custom response headers to all
* {@link YokeResponse}.
*
*
* Example:
*
*
*
* {@code
* yoke.use(new ResponseHeaders()
* .with("X-Build-Meta", "1.0-SNAPSHOT")
* .with("X-Server-Id", "server-123"));
* }
*
*/
public class ResponseHeaders extends Middleware
{
private final Map headers;
public ResponseHeaders()
{
headers = new HashMap<>();
}
public ResponseHeaders with(final CharSequence name, final CharSequence... values)
{
headers.put(name, values);
return this;
}
@Override
public void handle(@NotNull final YokeRequest request, @NotNull final Handler