Java 类com.sun.net.httpserver.HttpsExchange 实例源码

项目:OpenJSharp    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:openjdk-jdk10    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:openjdk9    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:lookaside_java-1.8.0-openjdk    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:infobip-open-jdk-8    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:las2peer-WebConnector    文件:WebConnectorRequestHandler.java   
private URI getBaseUri(final HttpExchange exchange, final String decodedBasePath) {
    final String scheme = (exchange instanceof HttpsExchange) ? "https" : "http";

    final URI baseUri;
    try {
        final List<String> hostHeader = exchange.getRequestHeaders().get("Host");
        if (hostHeader != null) {
            baseUri = new URI(scheme + "://" + hostHeader.get(0) + decodedBasePath);
        } else {
            final InetSocketAddress addr = exchange.getLocalAddress();
            baseUri = new URI(scheme, null, addr.getHostName(), addr.getPort(), decodedBasePath, null, null);
        }
    } catch (final URISyntaxException ex) {
        throw new IllegalArgumentException(ex);
    }
    return baseUri;
}
项目:OLD-OpenJDK8    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:openjdk-icedtea7    文件:ServerConnectionImpl.java   
@Override @NotNull
public String getBaseAddress() {
    /*
     * Computes the Endpoint's address from the request. Use "Host" header
     * so that it has correct address(IP address or someother hostname)
     * through which the application reached the endpoint.
     *
     */
    StringBuilder strBuf = new StringBuilder();
    strBuf.append((httpExchange instanceof HttpsExchange) ? "https" : "http");
    strBuf.append("://");

    String hostHeader = httpExchange.getRequestHeaders().getFirst("Host");
    if (hostHeader != null) {
        strBuf.append(hostHeader);   // Uses Host header
    } else {
        strBuf.append(httpExchange.getLocalAddress().getHostName());
        strBuf.append(":");
        strBuf.append(httpExchange.getLocalAddress().getPort());
    }
    //Do not include URL pattern here
    //strBuf.append(httpExchange.getRequestURI().getPath());

    return strBuf.toString();
}
项目:health-and-care-developer-network    文件:ResponseHeadersHelper.java   
@NotNull
public static Headers withoutEntityHeaders(@NotNull final HttpExchange httpExchange, @NotNull final String cacheControlHeaderValue)
{
    final Headers responseHeaders = httpExchange.getResponseHeaders();
    responseHeaders.set(ServerHeaderName, ServerHeaderValue);
    responseHeaders.set(DateHeaderName, rfc2822DateForNow());
    responseHeaders.set(ContentLanguageHeaderName, ContentLanguageHeaderValue);
    responseHeaders.set(ConnectionHeaderName, "close");
    final boolean isHttps = httpExchange instanceof HttpsExchange;
    if (isHttps)
    {
        responseHeaders.set(StrictTransportSecurityHeaderName, StrictTransportSecurityHeaderValueMaximum);
    }
    responseHeaders.set(XFrameOptionsHeaderName, "DENY");
    responseHeaders.set(XXssProtectionHeaderName, "1; mode=block");
    responseHeaders.set(XRimAutoMatchHeaderName, "none");
    responseHeaders.set(XRobotsTagHeaderName, "none");
    responseHeaders.set(AccessControlAllowOriginHeaderName, "*");
    responseHeaders.set(AccessControlAllowMethodsHeaderName, "POST, PUT, DELETE, GET, HEAD, OPTIONS");
    responseHeaders.set(AccessControlAllowHeadersHeaderName, "Authorization, Content-Type");
    responseHeaders.set(CacheControlHeaderName, cacheControlHeaderValue);
    responseHeaders.set(AcceptRangesHeaderName, "none");
    return responseHeaders;
}
项目:OpenJSharp    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:OpenJSharp    文件:ServerConnectionImpl.java   
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
项目:quorrabot    文件:HTTPSServer.java   
public void handle(HttpExchange httpExchange) throws IOException {
    HttpsExchange exchange = (HttpsExchange) httpExchange;
    Boolean hasPassword = false;
    String myPassword = "";
    String myHdrUser = "";
    String myHdrMessage = "";
    String[] uriQueryList = null;

    // Get the path and query string from the URI
    URI uriData = exchange.getRequestURI();
    String uriPath = uriData.getPath();
    String uriQuery = uriData.getQuery();

    if (uriQuery != null) {
        uriQueryList = uriQuery.split("&");
    }

    // Get the headers
    Headers headers = exchange.getRequestHeaders();

    // Get the Request Method (GET/PUT)
    String requestMethod = exchange.getRequestMethod();

    // Get any data from the body, although, we just discard it, this is required
    InputStream inputStream = exchange.getRequestBody();
    while (inputStream.read() != -1) {
        inputStream.skip(0x10000);
    }
    inputStream.close();

    if (headers.containsKey("password")) {
        myPassword = headers.getFirst("password");
        if (myPassword.equals(serverPassword) || myPassword.equals("oauth:" + serverPassword)) {
            hasPassword = true;
        }
    }
    if (headers.containsKey("webauth")) {
        myPassword = headers.getFirst("webauth");
        if (myPassword.equals(serverWebAuth)) {
            hasPassword = true;
        }
    }
    if (headers.containsKey("user")) {
        myHdrUser = headers.getFirst("user");
    }
    if (headers.containsKey("message")) {
        myHdrMessage = headers.getFirst("message");
    }

    if (requestMethod.equals("GET")) {
        if (uriPath.contains("..")) {
            sendHTMLError(403, "Invalid URL", exchange);
        } else if (uriPath.startsWith("/inistore")) {
            handleIniStore(uriPath, exchange, hasPassword);
        } else if (uriPath.startsWith("/dbquery")) {
            handleDBQuery(uriPath, uriQueryList, exchange, hasPassword);
        } else if (uriPath.startsWith("/addons") || uriPath.startsWith("/logs")) {
            handleFile(uriPath, exchange, hasPassword, true);
        } else if (uriPath.equals("/playlist")) {
            handleFile("/web/playlist/index.html", exchange, hasPassword, false);
        } else if (uriPath.equals("/")) {
            handleFile("/web/index.html", exchange, hasPassword, false);
        } else {
            handleFile("/web" + uriPath, exchange, hasPassword, false);
        }
    }

    if (requestMethod.equals("PUT")) {
        handlePutRequest(myHdrUser, myHdrMessage, exchange, hasPassword);
    }

}
项目:openjdk-jdk10    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:openjdk-jdk10    文件:ServerConnectionImpl.java   
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
项目:openjdk9    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:openjdk9    文件:ServerConnectionImpl.java   
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
项目:lookaside_java-1.8.0-openjdk    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:lookaside_java-1.8.0-openjdk    文件:ServerConnectionImpl.java   
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
项目:infobip-open-jdk-8    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:infobip-open-jdk-8    文件:ServerConnectionImpl.java   
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
项目:OLD-OpenJDK8    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:OLD-OpenJDK8    文件:ServerConnectionImpl.java   
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
项目:processeditor    文件:ExchangeRequestFacade.java   
@Override
public String getProtocol() {
    boolean isSecure = this.ex instanceof HttpsExchange;

    return ex.getProtocol().split("/")[0].toLowerCase() + (isSecure ? "s" : "");
}
项目:openjdk-icedtea7    文件:ServerConnectionImpl.java   
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
项目:vellumcore    文件:Httpx.java   
public SSLSession getSSLSession() {
    return ((HttpsExchange) delegate).getSSLSession();
}
项目:vellumcore    文件:Httpx.java   
public X509Certificate getPeerCertficate() throws SSLPeerUnverifiedException {
    return ((HttpsExchange) delegate).getSSLSession().getPeerCertificateChain()[0];        
}