Add Custom Header to the Response to Client

Procedure

  1. Get TrafficManagerResponse from the call context of an event.
  2. Get HTTPServerResponse from TrafficManagerResponse.
  3. 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);
        }
         
    }
    Note:

    Refer to the working code in examples/ AddHeaderPostProcessor.java.