com.clouway.friendlyserve.RequestHandlerMatchingParam Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fserve Show documentation
Show all versions of fserve Show documentation
Friendly Serving HTTP Library.
package com.clouway.friendlyserve;
import com.google.common.base.Optional;
import java.io.IOException;
/**
* RequestHandlerMatchingParam is an optional handler which could handle request only if the requested param is matching
* the provided value.
*
* An absent value will be returned when parameter value is not matching.
*
* @author Miroslav Genov ([email protected])
*/
public class RequestHandlerMatchingParam implements Fork {
private final String key;
private final String value;
private final Take take;
public RequestHandlerMatchingParam(String key, String value, Take take) {
this.key = key;
this.value = value;
this.take = take;
}
@Override
public Optional route(Request request) throws IOException {
String param = request.param(key);
if (value.equals(param)) {
return Optional.of(take.ack(request));
}
return Optional.absent();
}
}