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


Java Headers.put方法代码示例

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


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

示例1: handle

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange httpExchange) throws IOException {
    StringBuilder body = new StringBuilder();
    try (InputStreamReader reader = new InputStreamReader(httpExchange.getRequestBody(), Consts.UTF_8)) {
        char[] buffer = new char[256];
        int read;
        while ((read = reader.read(buffer)) != -1) {
            body.append(buffer, 0, read);
        }
    }
    Headers requestHeaders = httpExchange.getRequestHeaders();
    Headers responseHeaders = httpExchange.getResponseHeaders();
    for (Map.Entry<String, List<String>> header : requestHeaders.entrySet()) {
        responseHeaders.put(header.getKey(), header.getValue());
    }
    httpExchange.getRequestBody().close();
    httpExchange.sendResponseHeaders(statusCode, body.length() == 0 ? -1 : body.length());
    if (body.length() > 0) {
        try (OutputStream out = httpExchange.getResponseBody()) {
            out.write(body.toString().getBytes(Consts.UTF_8));
        }
    }
    httpExchange.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestClientSingleHostIntegTests.java

示例2: handle

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

    // some small sanity check
    List<String> cookies = reqHeaders.get("Cookie");
    for (String cookie : cookies) {
        if (!cookie.contains("JSESSIONID")
            || !cookie.contains("WILE_E_COYOTE"))
            t.sendResponseHeaders(400, -1);
    }

    // return some cookies so we can check getHeaderField(s)
    Headers respHeaders = t.getResponseHeaders();
    List<String> values = new ArrayList<>();
    values.add("ID=JOEBLOGGS; version=1; Path=" + URI_PATH);
    values.add("NEW_JSESSIONID=" + (SESSION_ID+1) + "; version=1; Path="
               + URI_PATH +"; HttpOnly");
    values.add("NEW_CUSTOMER=WILE_E_COYOTE2; version=1; Path=" + URI_PATH);
    respHeaders.put("Set-Cookie", values);
    values = new ArrayList<>();
    values.add("COOKIE2_CUSTOMER=WILE_E_COYOTE2; version=1; Path="
               + URI_PATH);
    respHeaders.put("Set-Cookie2", values);
    values.add("COOKIE2_JSESSIONID=" + (SESSION_ID+100)
               + "; version=1; Path=" + URI_PATH +"; HttpOnly");
    respHeaders.put("Set-Cookie2", values);

    t.sendResponseHeaders(200, -1);
    t.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:HttpOnly.java

示例3: setResponseHeaders

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
@Override
public void setResponseHeaders(Map<String,List<String>> headers) {
    Headers r = httpExchange.getResponseHeaders();
    r.clear();
    for(Map.Entry <String, List<String>> entry : headers.entrySet()) {
        String name = entry.getKey();
        List<String> values = entry.getValue();
        // ignore headers that interfere with our correct operations
        if (!"Content-Length".equalsIgnoreCase(name) && !"Content-Type".equalsIgnoreCase(name)) {
            r.put(name,new ArrayList<String>(values));
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:ServerConnectionImpl.java

示例4: setResponseHeaders

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
@Override
public void setResponseHeaders(Map<String,List<String>> headers) {
    Headers r = httpExchange.getResponseHeaders();
    r.clear();
    for(Map.Entry <String, List<String>> entry : headers.entrySet()) {
        String name = entry.getKey();
        List<String> values = entry.getValue();
        // ignore headers that interfere with our correct operations
        if (!name.equalsIgnoreCase("Content-Length") && !name.equalsIgnoreCase("Content-Type")) {
            r.put(name,new ArrayList<String>(values));
        }
    }
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:14,代码来源:ServerConnectionImpl.java

示例5: setDefaultContentType

import com.sun.net.httpserver.Headers; //导入方法依赖的package包/类
private void setDefaultContentType(Headers httpHeaders) {
    if (defaultContentType != null) {
        httpHeaders.put(CONTENT_TYPE, Collections.singletonList(defaultContentType));
    }
}
 
开发者ID:rockem,项目名称:blink-java,代码行数:6,代码来源:HttpExchangeBlinkResponse.java


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