This method handles the http session to be maintained between the calls.
In case the session is not needed or to be handled differently, then this
method can be overridden to do nothing or to roll your own feature.

@param serverResponse
@param headerKey
763835
public void handleHttpSession(Response serverResponse, String headerKey) {
        /** ---------------
         * Session handled
         * ----------------
         */
        if ("Set-Cookie".equals(headerKey)) {
            COOKIE_JSESSIONID_VALUE = serverResponse.getMetadata().get(headerKey);
        }
    }
108667
function Response(request, key) {

    // define private store
    const store = {
        body: '',
        cookies: [],
        headers: {},
        key: key,
        sent: false,
        statusCode: 0
    };
    this[STORE] = store;


    /**
     * The request that is tied to this response.
     * @name Response#req
     * @type {Request}
     */
    Object.defineProperty(this, 'req', {
        configurable: false,
        enumerable: true,
        value: request
    });

    /**
     * Determine if the response has already been sent.
     * @name Response#sent
     * @type {boolean}
     */
    Object.defineProperty(this, 'sent', {
        enumerable: true,
        get: () => store.sent
    });

    /**
     * Get the server instance that initialized this response.
     * @name Request#server
     * @type {SansServer}
     */
    Object.defineProperty(this, 'server', {
        enumerable: true,
        configurable: false,
        value: request.server
    });

    /**
     * Get a copy of the current response state.
     * @name Response#state
     * @type {ResponseState}
     */
    Object.defineProperty(this, 'state', {
        configurable: false,
        enumerable: true,
        get: () => {
            return {
                body: store.body,
                cookies: store.cookies.concat(),
                headers: Object.assign({}, store.headers),
                rawHeaders: rawHeaders(store.headers, store.cookies),
                statusCode: store.statusCode
            }
        }
    });

    /**
     * Get or set the status code.
     * @name Response#statusCode
     * @type {number}
     */
    Object.defineProperty(this, 'statusCode', {
        configurable: false,
        enumerable: true,
        get: () => store.statusCode,
        set: v => this.status(v)
    });

    /**
     * Produce a log event.
     * @param {string} message
     * @param {...*} [arg]
     * @returns {Response}
     * @fires Response#log
     */
    this.log = request.logger('sans-server', 'response', this);
}
1007085
@Override
    public final void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {

        AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
        if (authState.getAuthScheme() == null) {

            HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
            AuthCache authCache = new BasicAuthCache();
            authCache.put(targetHost, new BasicScheme());
            context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
        }
    }
452146
public void handle(ServerHttpRequest request, ServerHttpResponse response)
			throws IOException {
		handle(new HttpConnection(request, response));
	}
1193354
protected void doResponseHeaders(final HttpServletResponse response, final String mimeType) {
        if (mimeType != null) {
            response.setContentType(mimeType);
        }
    }
1004813
private void processRequestHeaders(HttpAcceptSession acceptSession, HttpConnectSession connectSession) {
        boolean upgrade = processHopByHopHeaders(acceptSession, connectSession);

        // Add Connection: upgrade or Connection: close header
        if (upgrade) {
            connectSession.setWriteHeader(HEADER_CONNECTION, HEADER_UPGRADE);
        } else {
            ResourceAddress address = connectSession.getRemoteAddress();
            // If keep-alive is disabled, add Connection: close header
            if (!address.getOption(HttpResourceAddress.KEEP_ALIVE)) {
                connectSession.setWriteHeader(HEADER_CONNECTION, "close");
            }
        }

        // Add Via: 1.1 kaazing + uuid header
        connectSession.addWriteHeader(HEADER_VIA, viaHeader);

        // Add forwarded headers
        setupForwardedHeaders(acceptSession, connectSession);

    }
1173202
void setHTTPResponse(HTTPResponse resp) {
        lock.lock();
        try {
            if (response != null) {
                throw(new IllegalStateException(
                        "HTTPResponse was already set"));
            }
            response = resp;
            ready.signalAll();
        } finally {
            lock.unlock();
        }
    }
329278
void handleService(KNXnetIPHeader h, byte[] data, int offset)
		throws KNXFormatException
	{
		final int svc = h.getServiceType();
		if (h.getVersion() != KNXNETIP_VERSION_10)
			close(ConnectionCloseEvent.INTERNAL, "protocol version changed",
				LogLevel.ERROR, null);
		else if (svc == KNXnetIPHeader.ROUTING_IND) {
			final RoutingIndication ind = new RoutingIndication(data, offset,
				h.getTotalLength() - h.getStructLength());
			fireFrameReceived(ind.getCEMI());
		}
		else if (svc == KNXnetIPHeader.ROUTING_LOST_MSG) {
			final RoutingLostMessage lost = new RoutingLostMessage(data, offset);
			fireLostMessage(lost);
		}
		else
			logger.warn("received unknown frame (service type 0x"
				+ Integer.toHexString(svc) + ") - ignored");
	}
1198205
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
    private static void applyHeader(final HttpServletResponse sresp,
        final String header) {
        final String[] parts = header.split(":");
        final String name = parts[0].trim();
        final String val = parts[1].trim();
        if ("set-cookie".equals(name.toLowerCase(Locale.getDefault()))) {
            for (final HttpCookie cck : HttpCookie.parse(header)) {
                sresp.addCookie(
                    new Cookie(cck.getName(), cck.getValue())
                );
            }
        } else {
            sresp.setHeader(name, val);
        }
    }
784945
@Override
    public void addHeader(String key, String value)
    {
        _conn.setRequestProperty(key, value);
    }
1230933
protected void setResponseHeaders(
        HttpServletRequest request,
        HttpServletResponse response,
        String filename,
        URL resourceURL) {

        String cacheControl = "public, max-age=0, must-revalidate";
        int resourceCacheTime = getCacheTime(filename);
        if (resourceCacheTime > 0) {
            cacheControl = "max-age=" + String.valueOf(resourceCacheTime);
        }
        response.setHeader("Cache-Control", cacheControl);
        response.setDateHeader("Expires", System.currentTimeMillis() + (resourceCacheTime * 1000));

        // Find the modification timestamp
        long lastModifiedTime = 0;
        URLConnection connection = null;
        try {
            connection = resourceURL.openConnection();
            lastModifiedTime = connection.getLastModified();
            // Remove milliseconds to avoid comparison problems (milliseconds
            // are not returned by the browser in the "If-Modified-Since"
            // header).
            lastModifiedTime = lastModifiedTime - (lastModifiedTime % 1000);
            response.setDateHeader("Last-Modified", lastModifiedTime);

            if (browserHasNewestVersion(request, lastModifiedTime)) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
        } catch (Exception e) {
            // Failed to find out last modified timestamp. Continue without it.
            LOG.debug("Failed to find out last modified timestamp. Continuing without it.", e);
        } finally {
            try {
                if (connection != null) {
                    // Explicitly close the input stream to prevent it
                    // from remaining hanging
                    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700
                    InputStream is = connection.getInputStream();
                    if (is != null) {
                        is.close();
                    }
                }
            } catch (Exception e) {
                LOG.info("Error closing URLConnection input stream", e);
            }
        }

        // Set type mime type if we can determine it based on the filename
        String mimetype = OpenCms.getResourceManager().getMimeType(filename, "UTF-8");
        if (mimetype != null) {
            response.setContentType(mimetype);
        }
    }
960144
public synchronized void setResponse(HttpServletResponse response) {

        if (perThreadResponse == null) {
            perThreadResponse = new ThreadLocal<HttpServletResponse>();
        }
        perThreadResponse.set(response);
    }
520299
private void copyResponseHeaders(HttpResponse proxyResponse, final HttpServletResponse servletResponse) {
        servletResponse.setCharacterEncoding(getContentCharSet(proxyResponse.getEntity()));
        from(Arrays.asList(proxyResponse.getAllHeaders())).filter(new Predicate<Header>() {
            @Override
            public boolean apply(Header header) {
                return !hopByHopHeaders.containsHeader(header.getName());
            }
        }).transform(new Function<Header, Boolean>() {
            @Override
            public Boolean apply(Header header) {
                servletResponse.addHeader(header.getName(), header.getValue());
                return true;
            }
        }).toList();
    }
1215629
public void sessionAccessUnknownKey(Object key) {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_CORE.logp(Level.FINE, methodClassName, "sessionAccessUnknownKey", "sessionObservers.size()=" + _sessionObservers.size());
        }
        if (_sessionObservers == null || _sessionObservers.size() < 1) {
            return;
        }

        // ArrayList sessionObservers = null;
        // synchronized(_sessionObservers) {
        // sessionObservers = (ArrayList)_sessionObservers.clone();
        // }

        ISessionObserver sessionObserver = null;
        for (int i = 0; i < _sessionObservers.size(); i++) {
            sessionObserver = (ISessionObserver) _sessionObservers.get(i);
            sessionObserver.sessionAccessUnknownKey(key);
        }

    }
729340
protected boolean handleResourceHeader(String key, String value) {
        if (ResourceResponse.HTTP_STATUS_CODE.equals(key)) {
            this.portletResourceOutputHandler.setStatus(Integer.parseInt(value));
            return true;
        }
        if ("Content-Type".equals(key)) {
            final ContentType contentType = ContentType.parse(value);
            final Charset charset = contentType.getCharset();
            if (charset != null) {
                this.portletResourceOutputHandler.setCharacterEncoding(charset.name());
            }
            this.portletResourceOutputHandler.setContentType(contentType.getMimeType());
            return true;
        }
        if ("Content-Length".equals(key)) {
            this.portletResourceOutputHandler.setContentLength(Integer.parseInt(value));
            return true;
        }
        if ("Content-Language".equals(key)) {
            final HeaderElement[] parts = BasicHeaderValueParser.parseElements(value, null);
            if (parts.length > 0) {
                final String localeStr = parts[0].getValue();
                final Locale locale = LocaleUtils.toLocale(localeStr);
                this.portletResourceOutputHandler.setLocale(locale);
                return true;
            }
        }

        return false;
    }
1254738
protected void subscriptionResponseReceived(IoSession session,
			SubscriptionMessage subscriptionMessage) {
		log.info("Received {}", subscriptionMessage);
		this.receivedSubscription = subscriptionMessage;

		if (this.sentSubscription == null) {
			log.error(
					"Protocol error: Received a subscription response without sending a request.\n{}",
					subscriptionMessage);
			this._disconnect();
			return;
		}

		if (!this.sentSubscription.equals(this.receivedSubscription)) {
			log.info(
					"Server did not fully accept subscription request.\nOriginal:\n{}\nAmended\n{}",
					this.sentSubscription, this.receivedSubscription);
		}

		for (ConnectionListener listener : this.connectionListeners) {
			listener.subscriptionReceived(this, subscriptionMessage);
		}
	}
392075
protected void doHead(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // Process request without content.
        processRequest(request, response, false);
    }