本文整理汇总了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();
}
示例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;
}
示例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);
}
示例5: getRequestScheme
import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
@Override
public String getRequestScheme() {
return (httpExchange instanceof HttpsExchange) ? "https" : "http";
}
示例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);
}
}
示例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" : "");
}
示例8: getSSLSession
import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
public SSLSession getSSLSession() {
return ((HttpsExchange) delegate).getSSLSession();
}
示例9: getPeerCertficate
import com.sun.net.httpserver.HttpsExchange; //导入依赖的package包/类
public X509Certificate getPeerCertficate() throws SSLPeerUnverifiedException {
return ((HttpsExchange) delegate).getSSLSession().getPeerCertificateChain()[0];
}