com.jetdrone.vertx.yoke.extras.middleware.ResponseHeaders Maven / Gradle / Ivy
package com.jetdrone.vertx.yoke.extras.middleware;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.vertx.java.core.Handler;
import com.jetdrone.vertx.yoke.Middleware;
import com.jetdrone.vertx.yoke.middleware.YokeRequest;
import com.jetdrone.vertx.yoke.middleware.YokeResponse;
/**
*
* 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(final YokeRequest request, final Handler