Added Cookie interceptor.

This commit is contained in:
petromykhailyshyn 2014-10-17 12:52:09 +03:00
parent 287162af91
commit 10c49d2bd3
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package ca.uhn.fhir.rest.client.interceptor;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import ca.uhn.fhir.rest.client.IClientInterceptor;
import ca.uhn.fhir.rest.server.Constants;
/**
* HTTP interceptor to be used for adding Cookie to requests.
* <p>
* This interceptor adds a header resembling the following:<br/>
* &nbsp;&nbsp;&nbsp;<code>Cookie: [key]=[value]</code><br/>
* </p>
*/
public class CookieInterceptor implements IClientInterceptor {
private final String sessionCookie;
public CookieInterceptor(String sessionCookie) {
this.sessionCookie = sessionCookie;
}
@Override
public void interceptRequest(HttpRequestBase theRequest) {
theRequest.addHeader(Constants.HEADER_COOKIE, sessionCookie); //$NON-NLS-1$
}
@Override
public void interceptResponse(HttpResponse theResponse) {
// nothing
}
}

View File

@ -56,6 +56,7 @@ public class Constants {
public static final String HEADER_CONTENT_LOCATION = "Content-Location";
public static final String HEADER_CONTENT_LOCATION_LC = HEADER_CONTENT_LOCATION.toLowerCase();
public static final String HEADER_CONTENT_TYPE = "Content-Type";
public static final String HEADER_COOKIE = "Cookie";
public static final String HEADER_CORS_ALLOW_METHODS = "Access-Control-Allow-Methods";
public static final String HEADER_CORS_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static final String HEADER_CORS_EXPOSE_HEADERS = "Access-Control-Expose-Headers";