当前位置: 首页>>代码示例>>Java>>正文


Java HttpsExchange类代码示例

本文整理汇总了Java中com.sun.net.httpserver.HttpsExchange的典型用法代码示例。如果您正苦于以下问题:Java HttpsExchange类的具体用法?Java HttpsExchange怎么用?Java HttpsExchange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpsExchange类属于com.sun.net.httpserver包,在下文中一共展示了HttpsExchange类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBaseAddress

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
@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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ServerConnectionImpl.java

示例2: getBaseUri

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
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;
}
 
开发者ID:rwth-acis,项目名称:las2peer-WebConnector,代码行数:18,代码来源:WebConnectorRequestHandler.java

示例3: withoutEntityHeaders

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
@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;
}
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:25,代码来源:ResponseHeadersHelper.java

示例4: isSecure

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
@Override
public boolean isSecure() {
    return (httpExchange instanceof HttpsExchange);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:ServerConnectionImpl.java

示例5: getRequestScheme

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
@Override
public String getRequestScheme() {
        return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:ServerConnectionImpl.java

示例6: handle

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
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);
    }

}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:73,代码来源:HTTPSServer.java

示例7: getProtocol

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
@Override
public String getProtocol() {
    boolean isSecure = this.ex instanceof HttpsExchange;

    return ex.getProtocol().split("/")[0].toLowerCase() + (isSecure ? "s" : "");
}
 
开发者ID:frapu78,项目名称:processeditor,代码行数:7,代码来源:ExchangeRequestFacade.java

示例8: getSSLSession

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
public SSLSession getSSLSession() {
    return ((HttpsExchange) delegate).getSSLSession();
}
 
开发者ID:evanx,项目名称:vellumcore,代码行数:4,代码来源:Httpx.java

示例9: getPeerCertficate

import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
public X509Certificate getPeerCertficate() throws SSLPeerUnverifiedException {
    return ((HttpsExchange) delegate).getSSLSession().getPeerCertificateChain()[0];        
}
 
开发者ID:evanx,项目名称:vellumcore,代码行数:4,代码来源:Httpx.java


注:本文中的com.sun.net.httpserver.HttpsExchange类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。