Java Code Examples for org.apache.http.HttpResponse#setHeaders()
The following examples show how to use
org.apache.http.HttpResponse#setHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConanClient.java From nexus-repository-conan with Eclipse Public License 1.0 | 7 votes |
public HttpResponse getHttpResponse(final String path) throws IOException { try (CloseableHttpResponse closeableHttpResponse = super.get(path)) { HttpEntity entity = closeableHttpResponse.getEntity(); BasicHttpEntity basicHttpEntity = new BasicHttpEntity(); String content = EntityUtils.toString(entity); basicHttpEntity.setContent(IOUtils.toInputStream(content)); basicHttpEntity.setContentEncoding(entity.getContentEncoding()); basicHttpEntity.setContentLength(entity.getContentLength()); basicHttpEntity.setContentType(entity.getContentType()); basicHttpEntity.setChunked(entity.isChunked()); StatusLine statusLine = closeableHttpResponse.getStatusLine(); HttpResponse response = new BasicHttpResponse(statusLine); response.setEntity(basicHttpEntity); response.setHeaders(closeableHttpResponse.getAllHeaders()); response.setLocale(closeableHttpResponse.getLocale()); return response; } }
Example 2
Source File: CachedHttpResponseGenerator.java From apigee-android-sdk with Apache License 2.0 | 6 votes |
/** * If I was able to use a {@link CacheEntry} to response to the * {@link org.apache.http.HttpRequest} then generate an {@link HttpResponse} * based on the cache entry. * * @param entry * {@link CacheEntry} to transform into an {@link HttpResponse} * @return {@link HttpResponse} that was constructed */ HttpResponse generateResponse(HttpCacheEntry entry) { Date now = new Date(); HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, entry.getStatusCode(), entry.getReasonPhrase()); HttpEntity entity = new CacheEntity(entry); response.setHeaders(entry.getAllHeaders()); addMissingContentLengthHeader(response, entity); response.setEntity(entity); long age = this.validityStrategy.getCurrentAgeSecs(entry, now); if (age > 0) { if (age >= Integer.MAX_VALUE) { response.setHeader(HeaderConstants.AGE, "2147483648"); } else { response.setHeader(HeaderConstants.AGE, "" + ((int) age)); } } return response; }
Example 3
Source File: SizeLimitedResponseReader.java From apigee-android-sdk with Apache License 2.0 | 6 votes |
HttpResponse getReconstructedResponse() throws IOException { ensureConsumed(); HttpResponse reconstructed = new BasicHttpResponse( response.getStatusLine()); reconstructed.setHeaders(response.getAllHeaders()); CombinedEntity combinedEntity = new CombinedEntity(resource, instream); HttpEntity entity = response.getEntity(); if (entity != null) { combinedEntity.setContentType(entity.getContentType()); combinedEntity.setContentEncoding(entity.getContentEncoding()); combinedEntity.setChunked(entity.isChunked()); } reconstructed.setEntity(combinedEntity); return reconstructed; }
Example 4
Source File: PhotatoHandler.java From Photato with GNU Affero General Public License v3.0 | 5 votes |
@Override public final void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { if (!this.allowedVerbs.contains(request.getRequestLine().getMethod().toUpperCase())) { response.setStatusCode(http403.responseCode); response.setEntity(http403.entity); } else { Tuple<String, Map<String, String>> pathAndQueryTuple = PathHelper.splitPathAndQuery(request.getRequestLine().getUri().substring(this.prefix.length())); String path = pathAndQueryTuple.o1; Map<String, String> query = pathAndQueryTuple.o2; if (this.isAuthorized(path, query)) { try { Response res = getResponse(path, query); response.setStatusCode(res.responseCode); response.setHeaders(res.headers); response.setEntity(res.entity); } catch (Exception ex) { response.setStatusCode(http500.responseCode); response.setEntity(http500.entity); ex.printStackTrace(); } } else { response.setStatusCode(http403.responseCode); response.setEntity(http403.entity); } } }
Example 5
Source File: FakeHttpStack.java From openshop.io-android with MIT License | 5 votes |
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> stringStringMap) throws IOException, AuthFailureError { HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK")); List<Header> headers = defaultHeaders(); response.setHeaders(headers.toArray(new Header[headers.size()])); //response.setLocale(Locale.JAPAN); response.setEntity(createEntity(request)); return response; }