Skip to content

Commit

Permalink
Merge pull request #35 from petromykhailysyn/master
Browse files Browse the repository at this point in the history
Added Cookie interceptor.
  • Loading branch information
jamesagnew committed Oct 17, 2014
2 parents 79f92e8 + 10c49d2 commit e31970f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e31970f

Please sign in to comment.