private void onPostFetch(Event event) {
        // Update caching policies
        FetchEvent e = (FetchEvent) event;

        String ourSurrogateId = e.getHttpRequest().getFirstHeader(H_X_SURROGATE_ID).getValue();

        SurrogateCapabilitiesHeader surrogateCapabilitiesHeader =
                SurrogateCapabilitiesHeader.fromHeaderValue(e.getHttpRequest().getFirstHeader(H_SURROGATE_CAPABILITIES)
                        .getValue());

        if (!e.getHttpResponse().containsHeader(H_SURROGATE_CONTROL)
                && surrogateCapabilitiesHeader.getSurrogates().size() > 1) {

            // Ensure another proxy can process the request

            LinkedHashMap<String, List<String>> targetCapabilities = new LinkedHashMap<>();
            initSurrogateMap(targetCapabilities, surrogateCapabilitiesHeader);
            for (String c : this.capabilities) {

                // Ignore Surrogate/1.0
                if ("Surrogate/1.0".equals(c)) {
                    continue;
                }

                String firstSurrogate = getFirstSurrogateFor(surrogateCapabilitiesHeader, c);

                // firstSurrogate cannot be null since we are the last surrogate.
                targetCapabilities.get(firstSurrogate).add(c);
            }

            fixSurrogateMap(targetCapabilities, ourSurrogateId);

            StringBuilder sb = new StringBuilder();
            boolean firstDevice = true;
            for (String device : targetCapabilities.keySet()) {
                if (targetCapabilities.get(device).size() == 0) {
                    continue;
                }

                if (!firstDevice) {
                    sb.append(", ");
                } else {
                    firstDevice = false;
                }

                sb.append("content=\"");
                boolean firstCap = true;
                for (String cap : targetCapabilities.get(device)) {
                    if (!firstCap) {
                        sb.append(" ");
                    } else {
                        firstCap = false;

                    }
                    sb.append(cap);

                }
                sb.append("\";");
                sb.append(device);

            }

            e.getHttpResponse().addHeader(H_SURROGATE_CONTROL, sb.toString());
        }

        if (!e.getHttpResponse().containsHeader(H_SURROGATE_CONTROL)) {
            return;
        }

        // If there is a Surrogate-Control header, add a Vary header to ensure content is not reuse when using a
        // different set of Surrogates
        e.getHttpResponse().addHeader("Vary", H_SURROGATE_CAPABILITIES);

        List<String> enabledCapabilities = new ArrayList<>();
        List<String> remainingCapabilities = new ArrayList<>();
        List<String> newSurrogateControlL = new ArrayList<>();
        List<String> newCacheContent = new ArrayList<>();

        String controlHeader = e.getHttpResponse().getFirstHeader(H_SURROGATE_CONTROL).getValue();
        String[] control = split(controlHeader, ",");

        for (String directiveAndTarget : control) {
            String directive = strip(directiveAndTarget);

            // Is directive targeted
            int targetIndex = directive.lastIndexOf(';');
            String target = null;

            if (targetIndex > 0) {
                target = directive.substring(targetIndex + 1);
                directive = directive.substring(0, targetIndex);
            }

            if (target != null && !target.equals(ourSurrogateId)) {
                // If directive is not targeted to current instance.
                newSurrogateControlL.add(strip(directiveAndTarget));

            } else if (directive.startsWith("content=\"")) {
                // Handle content

                String[] content = split(directive.substring("content=\"".length(), directive.length() - 1), " ");

                for (String contentCap : content) {
                    contentCap = strip(contentCap);
                    if (contains(this.capabilities, contentCap)) {
                        enabledCapabilities.add(contentCap);
                    } else {
                        remainingCapabilities.add(contentCap);
                    }
                }
                if (remainingCapabilities.size() > 0) {
                    newSurrogateControlL.add("content=\"" + join(remainingCapabilities, " ") + "\"");
                }
            } else if (directive.startsWith("max-age=")) {
                String[] maxAge = split(directive, "+");
                newCacheContent.add(maxAge[0]);
                // Freshness extension
                if (maxAge.length > 1) {
                    newCacheContent.add("stale-while-revalidate=" + maxAge[1]);
                    newCacheContent.add("stale-if-error=" + maxAge[1]);
                }

                newSurrogateControlL.add(directive);
            } else if (directive.startsWith("no-store")) {
                newSurrogateControlL.add(directive);
                newCacheContent.add(directive);
            } else {
                newSurrogateControlL.add(directive);
            }
        }

        e.getHttpResponse().setHeader(H_X_ENABLED_CAPABILITIES, join(enabledCapabilities, " "));
        e.getHttpResponse().setHeader(H_X_NEXT_SURROGATE_CONTROL, join(newSurrogateControlL, ", "));

        // If cache control must be updated.
        if (newCacheContent.size() > 0) {
            MoveResponseHeader.moveHeader(e.getHttpResponse(), "Cache-Control", H_X_ORIGINAL_CACHE_CONTROL);
            e.getHttpResponse().setHeader("Cache-Control", join(newCacheContent, ", "));
        }
    }
private void onPostFetch ( Event event ) { FetchEvent e = ( FetchEvent ) event ; String ourSurrogateId = e . getHttpRequest ( ) . getFirstHeader ( H_X_SURROGATE_ID ) . getValue ( ) ; SurrogateCapabilitiesHeader surrogateCapabilitiesHeader = SurrogateCapabilitiesHeader . fromHeaderValue ( e . getHttpRequest ( ) . getFirstHeader ( H_SURROGATE_CAPABILITIES ) . getValue ( ) ) ; if ( ! e . getHttpResponse ( ) . containsHeader ( H_SURROGATE_CONTROL ) && surrogateCapabilitiesHeader . getSurrogates ( ) . size ( ) > 1 ) { LinkedHashMap < String , List < String > > targetCapabilities = new LinkedHashMap < > ( ) ; initSurrogateMap ( targetCapabilities , surrogateCapabilitiesHeader ) ; for ( String c : this . capabilities ) { if ( "Surrogate/1.0" . equals ( c ) ) { continue ; } String firstSurrogate = getFirstSurrogateFor ( surrogateCapabilitiesHeader , c ) ; targetCapabilities . get ( firstSurrogate ) . add ( c ) ; } fixSurrogateMap ( targetCapabilities , ourSurrogateId ) ; StringBuilder sb = new StringBuilder ( ) ; boolean firstDevice = true ; for ( String device : targetCapabilities . keySet ( ) ) { if ( targetCapabilities . get ( device ) . size ( ) == 0 ) { continue ; } if ( ! firstDevice ) { sb . append ( ", " ) ; } else { firstDevice = false ; } sb . append ( "content=\"" ) ; boolean firstCap = true ; for ( String cap : targetCapabilities . get ( device ) ) { if ( ! firstCap ) { sb . append ( " " ) ; } else { firstCap = false ; } sb . append ( cap ) ; } sb . append ( "\";" ) ; sb . append ( device ) ; } e . getHttpResponse ( ) . addHeader ( H_SURROGATE_CONTROL , sb . toString ( ) ) ; } if ( ! e . getHttpResponse ( ) . containsHeader ( H_SURROGATE_CONTROL ) ) { return ; } e . getHttpResponse ( ) . addHeader ( "Vary" , H_SURROGATE_CAPABILITIES ) ; List < String > enabledCapabilities = new ArrayList < > ( ) ; List < String > remainingCapabilities = new ArrayList < > ( ) ; List < String > newSurrogateControlL = new ArrayList < > ( ) ; List < String > newCacheContent = new ArrayList < > ( ) ; String controlHeader = e . getHttpResponse ( ) . getFirstHeader ( H_SURROGATE_CONTROL ) . getValue ( ) ; String [ ] control = split ( controlHeader , "," ) ; for ( String directiveAndTarget : control ) { String directive = strip ( directiveAndTarget ) ; int targetIndex = directive . lastIndexOf ( ';' ) ; String target = null ; if ( targetIndex > 0 ) { target = directive . substring ( targetIndex + 1 ) ; directive = directive . substring ( 0 , targetIndex ) ; } if ( target != null && ! target . equals ( ourSurrogateId ) ) { newSurrogateControlL . add ( strip ( directiveAndTarget ) ) ; } else if ( directive . startsWith ( "content=\"" ) ) { String [ ] content = split ( directive . substring ( "content=\"" . length ( ) , directive . length ( ) - 1 ) , " " ) ; for ( String contentCap : content ) { contentCap = strip ( contentCap ) ; if ( contains ( this . capabilities , contentCap ) ) { enabledCapabilities . add ( contentCap ) ; } else { remainingCapabilities . add ( contentCap ) ; } } if ( remainingCapabilities . size ( ) > 0 ) { newSurrogateControlL . add ( "content=\"" + join ( remainingCapabilities , " " ) + "\"" ) ; } } else if ( directive . startsWith ( "max-age=" ) ) { String [ ] maxAge = split ( directive , "+" ) ; newCacheContent . add ( maxAge [ 0 ] ) ; if ( maxAge . length > 1 ) { newCacheContent . add ( "stale-while-revalidate=" + maxAge [ 1 ] ) ; newCacheContent . add ( "stale-if-error=" + maxAge [ 1 ] ) ; } newSurrogateControlL . add ( directive ) ; } else if ( directive . startsWith ( "no-store" ) ) { newSurrogateControlL . add ( directive ) ; newCacheContent . add ( directive ) ; } else { newSurrogateControlL . add ( directive ) ; } } e . getHttpResponse ( ) . setHeader ( H_X_ENABLED_CAPABILITIES , join ( enabledCapabilities , " " ) ) ; e . getHttpResponse ( ) . setHeader ( H_X_NEXT_SURROGATE_CONTROL , join ( newSurrogateControlL , ", " ) ) ; if ( newCacheContent . size ( ) > 0 ) { MoveResponseHeader . moveHeader ( e . getHttpResponse ( ) , "Cache-Control" , H_X_ORIGINAL_CACHE_CONTROL ) ; e . getHttpResponse ( ) . setHeader ( "Cache-Control" , join ( newCacheContent , ", " ) ) ; } }
<ul>
<li>Inject H_X_ENABLED_CAPABILITIES into response.</li>
<li>Consume capabilities. Does not support targeting yet.</li>
<li>Update caching directives.</li>
</ul>

@param event
Incoming fetch event.