List of usage examples for org.apache.http.message BasicHttpResponse setHeaders
public void setHeaders(Header[] headerArr)
From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java
/******************************************************************************************************************* * * //from w w w . j av a 2s . c om * ******************************************************************************************************************/ @Nonnull private static HttpResponse responseFrom(final @Nonnull HttpCacheEntry entry) { final BasicHttpResponse response = new BasicHttpResponse(entry.getStatusLine()); response.setHeaders(entry.getAllHeaders()); return response; }
From source file:com.android.volley.toolbox.BaseHttpStack.java
/** * @deprecated use {@link #executeRequest} instead to avoid a dependency on the deprecated * Apache HTTP library. Nothing in Volley's own source calls this method. However, since * {@link BasicNetwork#mHttpStack} is exposed to subclasses, we provide this implementation in * case legacy client apps are dependent on that field. This method may be removed in a future * release of Volley./* ww w . j a va 2s . c o m*/ */ @Deprecated @Override public final org.apache.http.HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpResponse response = executeRequest(request, additionalHeaders); ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); StatusLine statusLine = new BasicStatusLine(protocolVersion, response.getStatusCode(), "" /* reasonPhrase */); BasicHttpResponse apacheResponse = new BasicHttpResponse(statusLine); List<org.apache.http.Header> headers = new ArrayList<>(); for (Header header : response.getHeaders()) { headers.add(new BasicHeader(header.getName(), header.getValue())); } apacheResponse.setHeaders(headers.toArray(new org.apache.http.Header[headers.size()])); InputStream responseStream = response.getContent(); if (responseStream != null) { BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(responseStream); entity.setContentLength(response.getContentLength()); apacheResponse.setEntity(entity); } return apacheResponse; }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private HttpResponse buildResponse(Header[] allHeaders, int statusCode, String reasonPhrase, String serializedEntity) { BasicHttpResponse r = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), statusCode, reasonPhrase); r.setHeaders(allHeaders); if (serializedEntity != null) { BasicHttpEntity e = new BasicHttpEntity(); // TODO: use content-encoding header try {// w w w .java 2 s .c o m e.setContent(new ByteArrayInputStream(serializedEntity.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e1) { throw new UnsupportedOperationException(e1); } for (Header h : allHeaders) { if (h.getName().equalsIgnoreCase("Content-Type")) { e.setContentType(h.getValue()); } } e.setContentLength(serializedEntity.length()); r.setEntity(e); } return r; }