Java Code Examples for org.apache.http.HttpResponse#removeHeader()
The following examples show how to use
org.apache.http.HttpResponse#removeHeader() .
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: Surrogate.java From esigate with Apache License 2.0 | 5 votes |
private void removeVarySurrogateCapabilities(HttpResponse response) { // Remove Vary: Surrogate-Capabilities Header[] varyHeaders = response.getHeaders("Vary"); if (varyHeaders != null) { for (Header h : varyHeaders) { if (H_SURROGATE_CAPABILITIES.equals(h.getValue())) { response.removeHeader(h); break; } } } }
Example 2
Source File: HeaderProcessor.java From RoboZombie with Apache License 2.0 | 3 votes |
/** * <p>Accepts the {@link InvocationContext} along with the {@link HttpResponse} and retrieves all response * headers which are discovered in the {@link HttpResponse}. These are then injected into their matching * {@link StringBuilder} which are identified by @{@link Header} on the endpoint request definition. The * response headers and the in-out parameters are matched using the header name and all parameters with * a runtime value of {@code null} will be ignored.</p> * * @param context * the {@link InvocationContext} which is used to discover any @{@link Header} metadata in its * <i>request</i> and <i>args</i> * <br><br> * @param response * the {@link HttpResponse} whose headers are to be retrieved and injected in the in-out * {@link StringBuilder} parameters found on the request definition * <br><br> * @return the <i>same</i> deserialized response entity instance which was supplied as a parameter * <br><br> * @throws ResponseProcessorException * if the response-header retrieval or injection failed due to an unrecoverable error * <br><br> * @since 1.3.0 */ @Override protected Object process(InvocationContext context, HttpResponse response, Object content) { try { List<Map.Entry<Header, Object>> headers = Metadata.onParams(Header.class, context); String name; StringBuilder value; for (Map.Entry<Header, Object> header : headers) { if(header.getValue() instanceof StringBuilder) { name = header.getKey().value(); value = (StringBuilder)header.getValue(); org.apache.http.Header[] responseHeaders = response.getHeaders(name); if(responseHeaders != null && responseHeaders.length > 0) { String responseHeaderValue = responseHeaders[0].getValue(); value.replace(0, value.length(), responseHeaderValue == null? "" :responseHeaderValue); response.removeHeader(responseHeaders[0]); //remaining headers (equally named) processed if in-out params available } } } return content; } catch(Exception e) { throw new ResponseProcessorException(getClass(), context, e); } }