use of org.apache.http.message.HeaderGroup in project azure-tools-for-java by Microsoft.
the class SharedKeyHttpObservable method request.
@Override
public Observable<CloseableHttpResponse> request(final HttpRequestBase httpRequest, @Nullable final HttpEntity entity, final List<NameValuePair> parameters, final List<Header> addOrReplaceHeaders) {
// We add necessary information to a temporary header group which is used to generate shared keys
final HeaderGroup headerGroup = new HeaderGroup();
headerGroup.setHeaders(getDefaultHeaderGroup().getAllHeaders());
if (entity != null) {
// We need to set content-length to generate shared key. What need to be point out is that the
// HttpObservable auto adds this header and calculates length when executing, so the content-length header
// cannot be added to default header group in case of duplication.
headerGroup.addHeader(new BasicHeader("Content-Length", String.valueOf(entity.getContentLength())));
}
ofNullable(addOrReplaceHeaders).orElse(emptyList()).forEach(headerGroup::addHeader);
String key = cred.generateSharedKey(httpRequest, headerGroup, ofNullable(parameters).orElse(emptyList()));
getDefaultHeaderGroup().updateHeader(new BasicHeader("Authorization", key));
return super.request(httpRequest, entity, ofNullable(parameters).orElse(emptyList()), ofNullable(addOrReplaceHeaders).orElse(emptyList()));
}
Aggregations