All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clouway.friendlyserve.RequiresHeader Maven / Gradle / Ivy

There is a newer version: 0.1.5
Show newest version
package com.clouway.friendlyserve;

import java.io.IOException;

import static com.google.common.base.Strings.isNullOrEmpty;

/**
 * RequiresHeader is a decorator class over {@link Take} that checks whether the provided header is passed to the request
 * or not. If it's not passed then bad request is returned as response otherwise request is passed to provided origin.
 * 

This class is use-full as validation clause to verify that certain header is passed.

* * @author Miroslav Genov ([email protected]) */ public class RequiresHeader implements Take { private final String headerName; private final Take origin; public RequiresHeader(String headerName, Take origin) { this.headerName = headerName; this.origin = origin; } @Override public Response ack(Request request) throws IOException { String headerValue = request.header(headerName); if (isNullOrEmpty(headerValue)) { return new RsBadRequest(); } return origin.ack(request); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy