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


Java Headers.set方法代码示例

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


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

示例1: noTriple

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private void noTriple(HttpExchange he) {

        try {
            Headers responseHeaders = he.getResponseHeaders();
            FileHandler ext = new FileHandler();
            File tmp;
            responseHeaders.set(TYPE, PNG);
            ext.getFile(NOTRIPLE);
            tmp = new File(PAGESDIR + NOTRIPLE);
            he.sendResponseHeaders(200, tmp.length());
            try (OutputStream os = he.getResponseBody()) {
                Files.copy(tmp.toPath(), os);
                tmp.delete();
            }
        } catch (IOException ex) {
            Logger.getLogger(CompareHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
开发者ID:infovillasimius,项目名称:amr2Fred,代码行数:19,代码来源:CompareHandler.java

示例2: setCors

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
public static void setCors(Headers requestHeaders, Headers responseHeaders)
{
	
	String origin = requestHeaders.getFirst("Origin");
	
	if (origin == null)
		origin = "null";
	
	responseHeaders.set("Allow", "GET,PUT,POST,DELETE,OPTIONS");
	responseHeaders.set("Access-Control-Allow-Origin", origin);
	responseHeaders.set("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
	responseHeaders.set("Access-Control-Allow-Headers", "Content-Type");
	responseHeaders.set("Access-Control-Request-Methods", "GET,PUT,POST,DELETE,OPTIONS");
	responseHeaders.set("Access-Control-Request-Headers", "Content-Type");
	responseHeaders.set("Access-Control-Max-Age", "3600");
}
 
开发者ID:EricssonResearch,项目名称:trap,代码行数:17,代码来源:CORSUtil.java

示例3: doHandle

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
public void doHandle(final HttpExchange t) throws IOException {
    final String path = t.getRequestURI().getPath();
    final int i = path.indexOf("/", 1);
    final String cmd = path.substring(i + 1);
    s_logger.info("Get CMD request for " + cmd);
    if (cmd.equals("getstatus")) {
        final ConsoleProxyClientStatsCollector statsCollector = ConsoleProxy.getStatsCollector();

        final Headers hds = t.getResponseHeaders();
        hds.set("Content-Type", "text/plain");
        t.sendResponseHeaders(200, 0);
        final OutputStreamWriter os = new OutputStreamWriter(t.getResponseBody(), "UTF-8");
        statsCollector.getStatsReport(os);
        os.close();
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:ConsoleProxyCmdHandler.java

示例4: handleClientStart

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private void handleClientStart(final HttpExchange t, final ConsoleProxyClient viewer, final String title, final String guest) throws IOException {
    final List<String> languages = t.getRequestHeaders().get("Accept-Language");
    final String response = viewer.onAjaxClientStart(title, languages, guest);

    final Headers hds = t.getResponseHeaders();
    hds.set("Content-Type", "text/html");
    hds.set("Cache-Control", "no-cache");
    hds.set("Cache-Control", "no-store");
    t.sendResponseHeaders(200, response.length());

    final OutputStream os = t.getResponseBody();
    try {
        os.write(response.getBytes());
    } finally {
        os.close();
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:ConsoleProxyAjaxHandler.java

示例5: handle

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
public void handle(HttpExchange exchange) throws IOException {
  String requestMethod = exchange.getRequestMethod();
  if (requestMethod.equalsIgnoreCase("GET")) {
    boolean isHealthy = serverWithStats.isHealthy();
    Headers responseHeaders = exchange.getResponseHeaders();
    String response = "{ \"version\" : \"" + serverWithStats.getVersion() + "\"}";
    if (isHealthy) {
      responseHeaders.set("Content-Type", "text/html");
      exchange.sendResponseHeaders(200, response.getBytes().length);
    } else {
      responseHeaders.set("Content-Type", "text/html");
      exchange.sendResponseHeaders(500, response.getBytes().length);
    }
    OutputStream responseBody = exchange.getResponseBody();
    Headers requestHeaders = exchange.getRequestHeaders();
    responseBody.write(response.getBytes());
    responseBody.close();
  }
}
 
开发者ID:Altiscale,项目名称:transfer-accelerator,代码行数:20,代码来源:ServerStatus.java

示例6: handle

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
public void handle(HttpExchange exchange) throws IOException
{
    /*InputStream is = t.getRequestBody();
    String response = "response ok";
    t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length());
    OutputStream os = t.getResponseBody();
    os.write(response.getBytes());
    os.close();
    */
    Headers responseHeaders = exchange.getResponseHeaders();
	responseHeaders.set("Content-Type", "text/html");
	String response = ConfigContext.getRequest(ConfigContext.getProp("RSPE404"));
	exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, response.length());
	OutputStream os = exchange.getResponseBody();
	os.write(response.getBytes());
	os.close();
}
 
开发者ID:muzi666boy,项目名称:fourinone,代码行数:18,代码来源:ParkInetServer.java

示例7: handle

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
public void handle(HttpExchange t) throws IOException {

			StringWriter sw = new StringWriter();

			SuPoxyDataObject data = SunnyList.get(SunnyList.size()-1);

			sw.write(data.getJSONRaw());
			String response = sw.toString();

			Headers h = t.getResponseHeaders();
			h.set("Content-Type","application/json");

			t.sendResponseHeaders(200, response.length());
			OutputStream os = t.getResponseBody();
			os.write(response.getBytes());
			os.close();
		}
 
开发者ID:Tommy-LSA,项目名称:supoxy,代码行数:18,代码来源:SuPoxyServer.java

示例8: doHandle

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
public void doHandle(HttpExchange t) throws Exception {
    String path = t.getRequestURI().getPath();
    int i = path.indexOf("/", 1);
    String cmd = path.substring(i + 1);
    s_logger.info("Get CMD request for " + cmd);
    if (cmd.equals("getstatus")) {
        ConsoleProxyClientStatsCollector statsCollector = ConsoleProxy.getStatsCollector();

        Headers hds = t.getResponseHeaders();
        hds.set("Content-Type", "text/plain");
        t.sendResponseHeaders(200, 0);
        OutputStreamWriter os = new OutputStreamWriter(t.getResponseBody(),"UTF-8");
        statsCollector.getStatsReport(os);
        os.close();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:17,代码来源:ConsoleProxyCmdHandler.java

示例9: handleClientStart

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private void handleClientStart(HttpExchange t, ConsoleProxyClient viewer, String title, String guest) throws IOException {
    List<String> languages = t.getRequestHeaders().get("Accept-Language");
    String response = viewer.onAjaxClientStart(title, languages, guest);

    Headers hds = t.getResponseHeaders();
    hds.set("Content-Type", "text/html");
    hds.set("Cache-Control", "no-cache");
    hds.set("Cache-Control", "no-store");
    t.sendResponseHeaders(200, response.length());

    OutputStream os = t.getResponseBody();
    try {
        os.write(response.getBytes());
    } finally {
        os.close();
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:18,代码来源:ConsoleProxyAjaxHandler.java

示例10: withoutEntityHeaders

import com.sun.net.httpserver.Headers; //导入方法依赖的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

示例11: sendData

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private void sendData(String contentType, byte[] data, HttpExchange exchange) {
    Headers outHeaders = exchange.getResponseHeaders();
    outHeaders.set("Content-Type", contentType);
    try {
        exchange.sendResponseHeaders(200, data.length);
        OutputStream outputStream = exchange.getResponseBody();
        outputStream.write(data);
        outputStream.close();
    } catch (IOException ex) {
        sendHTMLError(500, "Server Error", exchange);
        com.gmt2001.Console.err.println("HTTPS Server: sendData()" + ex.getMessage());
        com.gmt2001.Console.err.logStackTrace(ex);
    }
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:15,代码来源:HTTPSServer.java

示例12: sendHTMLError

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private void sendHTMLError(int error, String message, HttpExchange exchange) {
    Headers outHeaders = exchange.getResponseHeaders();
    outHeaders.set("Context-Type", "text/text");
    try {
        exchange.sendResponseHeaders(error, message.length());
        OutputStream outputStream = exchange.getResponseBody();
        outputStream.write(message.getBytes());
        outputStream.close();
    } catch (IOException ex) {
        // Do not generate another HTML error, as we are already in sendHTMLError which failed.
        com.gmt2001.Console.err.println("HTTPS Server: sendHTMLError()" + ex.getMessage());
        com.gmt2001.Console.err.logStackTrace(ex);
    }
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:15,代码来源:HTTPSServer.java

示例13: getHttpHandler

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private HttpHandler getHttpHandler() {
    return new HttpHandler() {
        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            try {
                final Headers headers = httpExchange.getResponseHeaders();
                final String requestMethod = httpExchange.getRequestMethod().toUpperCase();
                switch (requestMethod) {
                    case METHOD_GET:
                        final String responseBody = getUrlComponent(httpExchange.getRequestURI());
                        headers.set(HEADER_CONTENT_TYPE,
                                String.format("%s; charset=%s", TYPE.getMimeType(httpExchange.getRequestURI().toString()), CHARSET));

                        final byte[] rawResponseBody = responseBody.getBytes(CHARSET);
                        httpExchange.sendResponseHeaders(STATUS_OK, rawResponseBody.length);
                        httpExchange.getResponseBody().write(rawResponseBody);
                        break;
                    case METHOD_OPTIONS:
                        headers.set(HEADER_ALLOW, ALLOWED_METHODS);
                        httpExchange.sendResponseHeaders(STATUS_OK, NO_RESPONSE_LENGTH);
                        break;
                    default:
                        headers.set(HEADER_ALLOW, ALLOWED_METHODS);
                        httpExchange.sendResponseHeaders(STATUS_METHOD_NOT_ALLOWED, NO_RESPONSE_LENGTH);
                        break;
                }
            } finally {
                httpExchange.close();
            }
        }
    };
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:33,代码来源:LocalHttpService.java

示例14: moved

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
void moved(HttpExchange t) throws IOException {
    Headers req = t.getRequestHeaders();
    Headers map = t.getResponseHeaders();
    URI uri = t.getRequestURI();
    String host = req.getFirst("Host");
    String location = "http://" + host + uri.getPath() + "/";
    map.set("Content-Type", "text/html");
    map.set("Location", location);
    t.sendResponseHeaders(301, -1);
    t.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SimpleHttpServer.java

示例15: writeResponse

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
void writeResponse(HttpExchange httpExchange, int code, String response) throws IOException {
    Headers headers = httpExchange.getResponseHeaders();
    headers.set("Content-Type", "application/json; charset=utf-8");
    httpExchange.sendResponseHeaders(code, response.length());
    try (OutputStream os = httpExchange.getResponseBody()) {
        os.write(response.getBytes());
    }
}
 
开发者ID:tumakha,项目名称:social-service,代码行数:9,代码来源:BaseHandlerImpl.java


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