Add Custom Header to the Response to Client
Procedure
- Get TrafficManagerResponse from the call context of an event.
- Get HTTPServerResponse from TrafficManagerResponse.
-
Get Headers from HTTPServerResponse and add new header to MutableHTTPHeaders list.
private static final String CUSTOM_HEADER="X-CUSTOM-HEADER"; private static final String CUSTOM_HEADER_VALUE="POST-PROCESSED"; @Override public void handleEvent(TrafficEvent event) { if(event instanceof PostProcessEvent){ Logger.debug(AddHeaderPostProcessor.class, "Handling post process event"); doPostProcessEvent((PostProcessEvent) event); } } private void doPostProcessEvent(PostProcessEvent event) { MutableHTTPHeaders headers = event.getCallContext().getResponse().getHTTPResponse().getHeaders(); if(event.getCallContext().getResponse().getHTTPResponse().getStatusCode() == 200){ headers.add(CUSTOM_HEADER,CUSTOM_HEADER_VALUE); } }
Copyright © 2022. Cloud Software Group, Inc. All Rights Reserved.