Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 package com.jetdrone.vertx.yoke.middleware;
 
 import java.util.Map;
 
 import  org.jetbrains.annotations.NotNull;
import  com.jetdrone.vertx.yoke.Middleware;

A simple Middleware that allows adding custom response headers to all YokeResponse.

Example:

 yoke.use(new ResponseHeaders()
          .with("X-Build-Meta", "1.0-SNAPSHOT")
          .with("X-Server-Id", "server-123"));
 
 
public class ResponseHeaders implements Middleware {
    private final Map<CharSequenceCharSequence[]> headers;
    public ResponseHeaders() {
         = new HashMap<>();
    }
    public ResponseHeaders with(final CharSequence namefinal CharSequence... values) {
        .put(namevalues);
        return this;
    }
    @Override
    public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Objectnext) {
        for (final Entry<CharSequenceCharSequence[]> header : .entrySet()) {
            request.response().headers().add(header.getKey(), Arrays.asList(header.getValue()));
        }
        next.handle(null);
    }
New to GrepCode? Check out our FAQ X