001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2014-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.http; 018 019import org.forgerock.http.protocol.Request; 020import org.forgerock.http.protocol.Response; 021import org.forgerock.services.context.Context; 022import org.forgerock.util.promise.NeverThrowsException; 023import org.forgerock.util.promise.Promise; 024 025/** 026 * Filters the request and/or response of an HTTP exchange. 027 */ 028public interface Filter { 029 /** 030 * Filters the request and/or response of an exchange. To pass the request 031 * to the next filter or handler in the chain, the filter calls 032 * {@code next.handle(context, request)}. 033 * <p> 034 * This method may elect not to pass the request to the next filter or 035 * handler, and instead handle the request itself. It can achieve this by 036 * merely avoiding a call to {@code next.handle(context, request)} 037 * and creating its own response object. The filter is also at liberty to 038 * replace a response with another of its own by intercepting the response 039 * returned by the next handler. 040 * 041 * @param context 042 * The request context. 043 * @param request 044 * The request. 045 * @param next 046 * The next filter or handler in the chain to handle the request. 047 * @return A {@code Promise} representing the response to be returned to the 048 * client. 049 */ 050 Promise<Response, NeverThrowsException> filter(Context context, Request request, Handler next); 051}