Java Code Examples for io.netty.handler.codec.http.HttpHeaders#setDate()

The following examples show how to use io.netty.handler.codec.http.HttpHeaders#setDate() . 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: ClientToProxyConnection.java    From g4proxy with Apache License 2.0 6 votes vote down vote up
private void writeAuthenticationRequired(String realm) {
    String body = "<!DOCTYPE HTML \"-//IETF//DTD HTML 2.0//EN\">\n"
            + "<html><head>\n"
            + "<title>407 Proxy Authentication Required</title>\n"
            + "</head><body>\n"
            + "<h1>Proxy Authentication Required</h1>\n"
            + "<p>This server could not verify that you\n"
            + "are authorized to access the document\n"
            + "requested.  Either you supplied the wrong\n"
            + "credentials (e.g., bad password), or your\n"
            + "browser doesn't understand how to supply\n"
            + "the credentials required.</p>\n" + "</body></html>\n";
    FullHttpResponse response = ProxyUtils.createFullHttpResponse(HttpVersion.HTTP_1_1,
            HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED, body);
    HttpHeaders.setDate(response, new Date());
    response.headers().set("Proxy-Authenticate",
            "Basic realm=\"" + (realm == null ? "Restricted Files" : realm) + "\"");
    write(response);
}
 
Example 2
Source File: ClientToProxyConnection.java    From g4proxy with Apache License 2.0 6 votes vote down vote up
/**
 * If and only if our proxy is not running in transparent mode, modify the
 * response headers to reflect that it was proxied.
 * 
 * @param httpResponse
 * @return
 */
private void modifyResponseHeadersToReflectProxying(
        HttpResponse httpResponse) {
    if (!proxyServer.isTransparent()) {
        HttpHeaders headers = httpResponse.headers();

        stripConnectionTokens(headers);
        stripHopByHopHeaders(headers);
        ProxyUtils.addVia(httpResponse, proxyServer.getProxyAlias());

        /*
         * RFC2616 Section 14.18
         * 
         * A received message that does not have a Date header field MUST be
         * assigned one by the recipient if the message will be cached by
         * that recipient or gatewayed via a protocol which requires a Date.
         */
        if (!headers.contains(HttpHeaders.Names.DATE)) {
            HttpHeaders.setDate(httpResponse, new Date());
        }
    }
}