private static class MD5CheckDispatcher extends Dispatcher {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
try {
MockResponse response = new MockResponse();
String expectedMd5 = request.getHeader("Content-MD5");
ByteSource body = ByteSource.wrap(request.getBody());
String realMd5FromRequest = base64().encode(body.hash(md5()).asBytes());
boolean matched = expectedMd5.equals(realMd5FromRequest);
if (matched) {
response.addHeader("x-Content-MD5", realMd5FromRequest);
} else {
response.setResponseCode(500);
}
return response;
} catch (IOException ex) {
throw Throwables.propagate(ex);
}