Java 类io.netty.handler.codec.http.cookie.DefaultCookie 实例源码

项目:whirlpool    文件:WebSocketHelper.java   
public static void realWriteAndFlush(Channel channel, String text, String contentType, boolean keepalive, DefaultCookie nettyCookie) {
    FullHttpResponse response = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1,
            HttpResponseStatus.OK,
            Unpooled.copiedBuffer(text + "\r\n", CharsetUtil.UTF_8));

    HttpUtil.setContentLength(response, text.length());
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
    setDateAndCacheHeaders(response, null);
    if (keepalive) {
        response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }

    if (nettyCookie != null) {
        response.headers().set(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(nettyCookie));
    }
    // Write the initial line and the header.
    channel.write(response);
    channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
}
项目:riposte    文件:HttpServletRequestWrapperForRequestInfoTest.java   
@Test
public void getCookies_returns_cookies_from_requestInfo() {
    // given
    Set<io.netty.handler.codec.http.cookie.Cookie> nettyCookies = new LinkedHashSet<>(Arrays.asList(
        new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString()),
        new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString())
    ));
    doReturn(nettyCookies).when(requestInfoMock).getCookies();

    List<Cookie> expectedCookieList = nettyCookies
        .stream().map(nc -> new Cookie(nc.name(), nc.value())).collect(Collectors.toList());

    // when
    Cookie[] result = wrapper.getCookies();

    // then
    for (int i = 0; i < result.length; i++) {
        Cookie expected = expectedCookieList.get(i);
        Cookie actual = result[i];
        assertThat(actual.getName()).isEqualTo(expected.getName());
        assertThat(actual.getValue()).isEqualTo(expected.getValue());
    }
}
项目:riposte    文件:BaseResponseInfoTest.java   
@Test
public void uber_constructor_for_full_response_sets_fields_as_expected() {
    // given
    int httpStatusCode = 200;
    HttpHeaders headers = new DefaultHttpHeaders();
    String mimeType = "text/text";
    Charset contentCharset = CharsetUtil.UTF_8;
    Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
    boolean preventCompressedResponse = true;

    // when
    BaseResponseInfo<?> responseInfo = createNewBaseResponseInfoForTesting(httpStatusCode, headers, mimeType, contentCharset, cookies, preventCompressedResponse);

    // then
    assertThat(responseInfo.getHttpStatusCode(), is(httpStatusCode));
    assertThat(responseInfo.getHeaders(), is(headers));
    assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
    assertThat(responseInfo.getDesiredContentWriterEncoding(), is(contentCharset));
    assertThat(responseInfo.getCookies(), is(cookies));
    assertThat(responseInfo.getUncompressedRawContentLength(), nullValue());
    assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedResponse));
    assertThat(responseInfo.isResponseSendingStarted(), is(false));
    assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));
}
项目:riposte    文件:HttpUtilsTest.java   
@Test
public void extractCookies_works_if_cookies_defined_in_headers() {
    // given
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));

    HttpRequest nettyRequestMock = mock(HttpRequest.class);
    doReturn(headers).when(nettyRequestMock).headers();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
}
项目:riposte    文件:HttpUtilsTest.java   
@Test
public void extractCookies_works_if_cookies_defined_in_trailing_headers() {
    // given
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HttpHeaders trailingHeaders = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));

    FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
    doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
    doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
}
项目:riposte    文件:HttpUtilsTest.java   
@Test
public void extractCookies_handles_cookie_values_leniently() {
    // given
    //these are cookie values seen in the wild...
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), "2094%3Az%7C2021%3Ab");
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), "geoloc=cc=US,rc=OR,tp=vhigh,tz=PST,la=45.4978,lo=-122.6937,bw=5000");
    Cookie cookie3 = new DefaultCookie(UUID.randomUUID().toString(), "\"dm=n.com&si=27431295-a282-4745-8cd5-542e7fce" +
            "429e&ss=1477551008358&sl=76&tt=437632&obo=12&sh=1477552753923%3D76%3A12%3A437632%2C1477552698670%3D75%3" +
            "A12%3A429879%2C1477552677137%3D74%3A12%3A426596%2C1477552672564%3D73%3A12%3A425585%2C1477552669893%3D72" +
            "%3A12%3A423456&bcn=%2F%2F3408178b.mpstat.us%2F&ld=1477552753923&r=http%3A%2F%2Fwww.nike.com%2Fbe%2Fde_de%" +
            "2F&ul=1477552756811\"");
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2, cookie3));

    HttpRequest nettyRequestMock = mock(HttpRequest.class);
    doReturn(headers).when(nettyRequestMock).headers();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
    assertThat(extractedCookies.contains(cookie3), is(true));
}
项目:nomulus    文件:EppServiceHandlerTest.java   
@Test
public void testSuccess_setCookies() throws Exception {
  setHandshakeSuccess();
  // First inbound message is hello.
  channel.readInbound();
  String responseContent = "<epp>response</epp>";
  Cookie cookie1 = new DefaultCookie("name1", "value1");
  Cookie cookie2 = new DefaultCookie("name2", "value2");
  channel.writeOutbound(
      makeEppHttpResponse(responseContent, HttpResponseStatus.OK, cookie1, cookie2));
  ByteBuf response = channel.readOutbound();
  assertThat(response).isEqualTo(Unpooled.wrappedBuffer(responseContent.getBytes(UTF_8)));
  String requestContent = "<epp>request</epp>";
  channel.writeInbound(Unpooled.wrappedBuffer(requestContent.getBytes(UTF_8)));
  FullHttpRequest request = channel.readInbound();
  assertHttpRequestEquivalent(request, makeEppHttpRequest(requestContent, cookie1, cookie2));
  // Nothing further to pass to the next handler.
  assertThat((Object) channel.readInbound()).isNull();
  assertThat((Object) channel.readOutbound()).isNull();
  assertThat(channel.isActive()).isTrue();
}
项目:netty-rest    文件:Response.java   
public Response addCookie(String name, String value, String domain, Boolean isHttpOnly, Long maxAge, String path, Boolean isSecured) {
    if(cookies == null) {
        cookies = Lists.newArrayList();
    }
    final DefaultCookie defaultCookie = new DefaultCookie(name, value);
    if(domain != null) {
        defaultCookie.setDomain(domain);
    }
    if(isHttpOnly != null) {
        defaultCookie.setHttpOnly(isHttpOnly);
    }
    if(maxAge != null) {
        defaultCookie.setMaxAge(maxAge);
    }
    if(path != null) {
        defaultCookie.setPath(path);
    }
    if(isSecured != null) {
        defaultCookie.setSecure(isSecured);
    }
    cookies.add(defaultCookie);
    return this;
}
项目:glowroot    文件:HttpSessionManager.java   
private CommonResponse createSession(String username, Set<String> roles, boolean ldap)
        throws Exception {
    String sessionId = new BigInteger(130, secureRandom).toString(32);
    ImmutableSession session = ImmutableSession.builder()
            .caseAmbiguousUsername(username)
            .ldap(ldap)
            .roles(roles)
            .lastRequest(clock.currentTimeMillis())
            .build();
    sessionMap.put(sessionId, session);

    String layoutJson = layoutService
            .getLayoutJson(session.createAuthentication(central, configRepository));
    CommonResponse response = new CommonResponse(OK, MediaType.JSON_UTF_8, layoutJson);
    Cookie cookie =
            new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), sessionId);
    cookie.setHttpOnly(true);
    cookie.setPath("/");
    response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
    purgeExpiredSessions();

    auditSuccessfulLogin(username);
    return response;
}
项目:rakam    文件:WebUserHttpService.java   
private FullHttpResponse unauthorized(Optional<String> jsonp) {
    String encode = JsonHelper.jsonObject()
            .put("success", false)
            .put("message", UNAUTHORIZED.reasonPhrase())
            .put("authentication", config.getAuthentication())
            .put("googleApiKey", config.getGoogleClientId()).toString();
    if (jsonp.isPresent()) {
        encode = jsonp.get() + "(" + encode + ")";
    }
    DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK,
            wrappedBuffer(encode.getBytes(CharsetUtil.UTF_8)));

    DefaultCookie cookie = new DefaultCookie("session", "");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(0);
    response.headers().add(SET_COOKIE, STRICT.encode(cookie));
    response.headers().set(CONTENT_TYPE, "application/json; charset=utf-8");
    return response;
}
项目:rakam    文件:UserIdEventMapper.java   
@Override
public List<Cookie> map(Event event, RequestParams requestParams, InetAddress sourceAddress, HttpHeaders responseHeaders) {
    GenericRecord properties = event.properties();

    if (properties.get("_user") == null) {
        Schema.Field user = event.properties().getSchema().getField("_user");
        if (user == null) {
            return null;
        }

        Schema.Type type = user.schema().getTypes().get(1).getType();
        Object anonymousUser = requestParams.cookies().stream()
                .filter(e -> e.name().equals("_anonymous_user")).findAny()
                .map(e -> cast(type, e.value())).orElse(generate(type));

        properties.put("_user", anonymousUser);
        DefaultCookie cookie = new DefaultCookie("_anonymous_user", String.valueOf(anonymousUser));
        cookie.setPath("/");

        return ImmutableList.of(cookie);
    }

    return null;
}
项目:wisdom    文件:CookieHelper.java   
/**
 * Converts the Wisdom's cookie to a Netty's cookie.
 *
 * @param cookie the Wisdom's cookie
 * @return the Netty's cookie with the same metadata and content than the input cookie.
 */
public static DefaultCookie convertWisdomCookieToNettyCookie(Cookie cookie) {
    DefaultCookie nettyCookie = new DefaultCookie(cookie.name(), cookie.value());
    nettyCookie.setMaxAge(cookie.maxAge());
    // Comments are not supported anymore by netty.
    if (cookie.domain() != null) {
        nettyCookie.setDomain(cookie.domain());
    }
    if (cookie.isSecure()) {
        nettyCookie.setSecure(true);
    }
    if (cookie.path() != null) {
        nettyCookie.setPath(cookie.path());
    }
    if (cookie.isHttpOnly()) {
        nettyCookie.setHttpOnly(true);
    }
    return nettyCookie;
}
项目:redant    文件:UserController.java   
@RouterMapping(path="/info",requestMethod=RequestMethod.GET,renderType=RenderType.JSON)
public CookieRender getUserInfo(UserBean userBean, @RouterParam(key="pid") Integer pid){
    JSONObject object = new JSONObject();
    object.put("user",userService.selectUserInfo(userBean.getId()));
    object.put("pid",pid);
    CookieRender render = new DefaultCookieRender(RenderType.JSON,object);
    // 设置Cookie
    render.setCookie(new DefaultCookie("ak","47"));
    return render;
}
项目:redant    文件:CookieHelper.java   
/**
 * 添加一个Cookie
 * @param response response
 * @param name  cookie名字
 * @param value cookie值
 * @param domain cookie所在域
 * @param maxAge cookie生命周期  以秒为单位
 */
public static void addCookie(HttpResponse response,String name,String value,String domain,long maxAge){
    Cookie cookie = new DefaultCookie(name,value);
    cookie.setPath("/");
    if(domain!=null && domain.trim().length()>0) {
        cookie.setDomain(domain);
    }
    if(maxAge>0){
        cookie.setMaxAge(maxAge);
    }
    setCookie(response,cookie);
}
项目:groot    文件:RequestExecutorService.java   
private void saveCookies(final CharSequence headerKey, final CharSequence headerValue) {
    if (headerKey.toString().equalsIgnoreCase(SET_COOKIE)) {
        String rawValue = String.valueOf(headerValue);
        int idx = rawValue.indexOf(";");
        String cookie = rawValue.substring(0, idx).trim();
        idx = cookie.indexOf("=");
        String cookieName = cookie.substring(0, idx).trim();
        String cookieValue = cookie.substring(idx + 1).trim();
        cookieStorage.add(new DefaultCookie(cookieName, cookieValue));
    }
}
项目:whirlpool    文件:WebSocketHelper.java   
public static DefaultCookie createCookie(String authCookieName, String domainName, String value, Long maxAge) {
    DefaultCookie nettyCookie = new DefaultCookie(authCookieName, value);
    nettyCookie.setMaxAge(maxAge);
    nettyCookie.setHttpOnly(false);
    nettyCookie.setPath("/");
    if (domainName != null && !"none".equals(domainName)) {
        nettyCookie.setDomain(domainName);
    }
    return nettyCookie;
}
项目:analytics-with-rfx    文件:BaseHttpLogHandler.java   
public static Cookie createCookie(String name, String value, String domain,
        String path) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setDomain(domain);
    cookie.setPath(path);
    return cookie;
}
项目:nebo    文件:NettyHttpServletResponse.java   
/**
     * Get a Netty {@link io.netty.handler.codec.http.HttpResponse}, committing the {@link javax.servlet.http.HttpServletResponse}.
     */
    public HttpResponse getNettyResponse() {
        if (committed) {
            return response;
        }
        committed = true;
        HttpHeaders headers = response.headers();
        if (null != contentType) {
            String value = null == characterEncoding ? contentType : contentType + "; charset=" + characterEncoding;
            headers.set(HttpHeaders.Names.CONTENT_TYPE, value);
        }else {
            headers.set(HttpHeaders.Names.CONTENT_TYPE,
                    DEFAULT_CONTENT_TYPE);
        }

        headers.set(HttpHeaders.Names.DATE, new Date());
        headers.set(HttpHeaders.Names.SERVER, servletContext.getServerInfoAscii());

        for(Cookie ck : cookies) {
            io.netty.handler.codec.http.cookie.Cookie  nettyCookie = new DefaultCookie(ck.getName(),ck.getValue());
            nettyCookie.setDomain(ck.getDomain());
            nettyCookie.setPath(ck.getPath());
            if( ck.getMaxAge()  > 0) {
                nettyCookie.setMaxAge(ck.getMaxAge());
            }
//            response.headers().add("Set-Cookie", nettyCookie);
           response.headers().add("Set-Cookie", ServerCookieEncoder.STRICT.encode(nettyCookie));
        }
        return response;
    }
项目:riposte    文件:BaseResponseInfoBuilderTest.java   
@Test
public void builder_stores_values_as_expected() {
    // given
    String content = UUID.randomUUID().toString();
    int httpStatusCode = 200;
    HttpHeaders headers = new DefaultHttpHeaders();
    String mimeType = "text/text";
    Charset contentCharset = CharsetUtil.ISO_8859_1;
    Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
    boolean preventCompressedOutput = true;

    // when
    BaseResponseInfoBuilder<String> responseInfoBuilder = new BaseResponseInfoBuilder<String>(){}
            .withHttpStatusCode(httpStatusCode)
            .withHeaders(headers)
            .withDesiredContentWriterMimeType(mimeType)
            .withDesiredContentWriterEncoding(contentCharset).withCookies(cookies)
            .withPreventCompressedOutput(preventCompressedOutput);

    // then
    assertThat(responseInfoBuilder.getHttpStatusCode(), is(httpStatusCode));
    assertThat(responseInfoBuilder.getHeaders(), is(headers));
    assertThat(responseInfoBuilder.getDesiredContentWriterMimeType(), is(mimeType));
    assertThat(responseInfoBuilder.getDesiredContentWriterEncoding(), is(contentCharset));
    assertThat(responseInfoBuilder.getCookies(), is(cookies));
    assertThat(responseInfoBuilder.isPreventCompressedOutput(), is(preventCompressedOutput));
}
项目:riposte    文件:FullResponseInfoTest.java   
@Test
public void uber_constructor_for_full_response_sets_fields_as_expected() {
    // given
    String content = UUID.randomUUID().toString();
    int httpStatusCode = 200;
    HttpHeaders headers = new DefaultHttpHeaders();
    String mimeType = "text/text";
    Charset contentCharset = CharsetUtil.UTF_8;
    Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
    boolean preventCompressedResponse = true;

    // when
    FullResponseInfo<String> responseInfo = new FullResponseInfo<>(content, httpStatusCode, headers, mimeType, contentCharset, cookies, preventCompressedResponse);

    // then
    assertThat(responseInfo.getContentForFullResponse(), is(content));
    assertThat(responseInfo.getHttpStatusCode(), is(httpStatusCode));
    assertThat(responseInfo.getHeaders(), is(headers));
    assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
    assertThat(responseInfo.getDesiredContentWriterEncoding(), is(contentCharset));
    assertThat(responseInfo.getCookies(), is(cookies));
    assertThat(responseInfo.getUncompressedRawContentLength(), nullValue());
    assertThat(responseInfo.getFinalContentLength(), nullValue());
    assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedResponse));
    assertThat(responseInfo.isChunkedResponse(), is(false));
    assertThat(responseInfo.isResponseSendingStarted(), is(false));
    assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));
}
项目:riposte    文件:FullResponseInfoTest.java   
@Test
public void builder_sets_values_as_expected() {
    // given
    String content = UUID.randomUUID().toString();
    int httpStatusCode = 200;
    HttpHeaders headers = new DefaultHttpHeaders();
    String mimeType = "text/text";
    Charset contentCharset = CharsetUtil.ISO_8859_1;
    Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
    boolean preventCompressedOutput = true;

    // when
    FullResponseInfo<String> responseInfo = ResponseInfo.<String>newBuilder()
                                                    .withContentForFullResponse(content)
                                                    .withHttpStatusCode(httpStatusCode)
                                                    .withHeaders(headers)
                                                    .withDesiredContentWriterMimeType(mimeType)
                                                    .withDesiredContentWriterEncoding(contentCharset).withCookies(cookies)
                                                    .withPreventCompressedOutput(preventCompressedOutput).build();

    // then
    assertThat(responseInfo.getContentForFullResponse(), is(content));
    assertThat(responseInfo.getHttpStatusCode(), is(httpStatusCode));
    assertThat(responseInfo.getHeaders(), is(headers));
    assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
    assertThat(responseInfo.getDesiredContentWriterEncoding(), is(contentCharset));
    assertThat(responseInfo.getCookies(), is(cookies));
    assertThat(responseInfo.getUncompressedRawContentLength(), nullValue());
    assertThat(responseInfo.getFinalContentLength(), nullValue());
    assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedOutput));
    assertThat(responseInfo.isChunkedResponse(), is(false));
    assertThat(responseInfo.isResponseSendingStarted(), is(false));
    assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));
}
项目:riposte    文件:ChunkedResponseInfoTest.java   
@Test
public void uber_constructor_for_chunked_response_sets_fields_as_expected() {
    // given
    int httpStatusCode = 200;
    HttpHeaders headers = new DefaultHttpHeaders();
    String mimeType = "text/text";
    Charset contentCharset = CharsetUtil.UTF_8;
    Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
    boolean preventCompressedResponse = true;

    // when
    ChunkedResponseInfo responseInfo = new ChunkedResponseInfo(httpStatusCode, headers, mimeType, contentCharset, cookies, preventCompressedResponse);

    // then
    assertThat(responseInfo.getHttpStatusCode(), is(httpStatusCode));
    assertThat(responseInfo.getHeaders(), is(headers));
    assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
    assertThat(responseInfo.getDesiredContentWriterEncoding(), is(contentCharset));
    assertThat(responseInfo.getCookies(), is(cookies));
    assertThat(responseInfo.getUncompressedRawContentLength(), nullValue());
    assertThat(responseInfo.getFinalContentLength(), nullValue());
    assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedResponse));
    assertThat(responseInfo.isChunkedResponse(), is(true));
    assertThat(responseInfo.isResponseSendingStarted(), is(false));
    assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));

}
项目:zbus    文件:MonitorAdaptor.java   
public void handle(Message msg, Session sess) throws IOException {  
    if("GET".equals(msg.getMethod())){
        ReplyKit.replyTemplate(msg, sess, "login.htm"); 
        return;
    } 

    Map<String, String> data = StrKit.kvp(msg.getBodyString(), "&"); 
    String tokenstr = null;
    if(data.containsKey(Protocol.TOKEN)) {
        tokenstr = data.get(Protocol.TOKEN);
    }
    Token token = authProvider.getToken(tokenstr); 

    Message res = new Message(); 
    if(token == null){
        res.setHeader("location", "/?cmd=login"); 
        res.setStatus(302); 
        sess.write(res);
        return;
    } 

    if(token != null){
        Cookie cookie = new DefaultCookie(Protocol.TOKEN, tokenstr); 
        res.setHeader("Set-Cookie", ServerCookieEncoder.STRICT.encode(cookie));
    } 
    res.setHeader("location", "/"); 
    res.setStatus(302); //redirect to home page
    sess.write(res);
}
项目:zbus    文件:MonitorAdaptor.java   
public void handle(Message msg, Session sess) throws IOException {  
    Message res = new Message();  
    res.setId(msg.getId());
    res.setHeader("location", "/?cmd=login"); 

    Cookie cookie = new DefaultCookie(Protocol.TOKEN, "");
    cookie.setMaxAge(0);
    res.setHeader("Set-Cookie", ServerCookieEncoder.STRICT.encode(cookie)); 
    res.setStatus(302); 
    sess.write(res); 
}
项目:nomulus    文件:EppServiceHandlerTest.java   
@Test
public void testSuccess_updateCookies() throws Exception {
  setHandshakeSuccess();
  // First inbound message is hello.
  channel.readInbound();
  String responseContent1 = "<epp>response1</epp>";
  Cookie cookie1 = new DefaultCookie("name1", "value1");
  Cookie cookie2 = new DefaultCookie("name2", "value2");
  // First response written.
  channel.writeOutbound(
      makeEppHttpResponse(responseContent1, HttpResponseStatus.OK, cookie1, cookie2));
  channel.readOutbound();
  String requestContent1 = "<epp>request1</epp>";
  // First request written.
  channel.writeInbound(Unpooled.wrappedBuffer(requestContent1.getBytes(UTF_8)));
  FullHttpRequest request1 = channel.readInbound();
  assertHttpRequestEquivalent(request1, makeEppHttpRequest(requestContent1, cookie1, cookie2));
  String responseContent2 = "<epp>response2</epp>";
  Cookie cookie3 = new DefaultCookie("name3", "value3");
  Cookie newCookie2 = new DefaultCookie("name2", "newValue");
  // Second response written.
  channel.writeOutbound(
      makeEppHttpResponse(responseContent2, HttpResponseStatus.OK, cookie3, newCookie2));
  channel.readOutbound();
  String requestContent2 = "<epp>request2</epp>";
  // Second request written.
  channel.writeInbound(Unpooled.wrappedBuffer(requestContent2.getBytes(UTF_8)));
  FullHttpRequest request2 = channel.readInbound();
  // Cookies in second request should be updated.
  assertHttpRequestEquivalent(
      request2, makeEppHttpRequest(requestContent2, cookie1, newCookie2, cookie3));
  // Nothing further to pass to the next handler.
  assertThat((Object) channel.readInbound()).isNull();
  assertThat((Object) channel.readOutbound()).isNull();
  assertThat(channel.isActive()).isTrue();
}
项目:bridje-framework    文件:HttpBridletResponseImpl.java   
@Override
public HttpCookie addCookie(String name, String value)
{
    if(cookies == null)
    {
        cookies = new HashMap<>();
    }
    HttpCookieImpl c = new HttpCookieImpl(new DefaultCookie(name, value));
    cookies.put(c.getName(), c);
    return c;
}
项目:bridje-framework    文件:HttpBridletResponseImpl.java   
@Override
public HttpCookie addCookie(String name, String value, String path)
{
    if(cookies == null)
    {
        cookies = new HashMap<>();
    }
    HttpCookieImpl c = new HttpCookieImpl(new DefaultCookie(name, value));
    c.setPath(path);
    cookies.put(c.getName(), c);
    return c;
}
项目:bridje-framework    文件:HttpBridletResponseImpl.java   
@Override
public HttpCookie addCookie(String name, String value, String path, String domain)
{
    if(cookies == null)
    {
        cookies = new HashMap<>();
    }
    HttpCookieImpl c = new HttpCookieImpl(new DefaultCookie(name, value));
    c.setPath(path);
    c.setDomain(domain);
    cookies.put(c.getName(), c);
    return c;
}
项目:bridje-framework    文件:HttpBridletResponseImpl.java   
@Override
public HttpCookie addCookie(String name, String value, String path, String domain, int maxAge)
{
    if(cookies == null)
    {
        cookies = new HashMap<>();
    }
    HttpCookieImpl c = new HttpCookieImpl(new DefaultCookie(name, value));
    c.setPath(path);
    c.setDomain(domain);
    c.setMaxAge(maxAge);
    cookies.put(c.getName(), c);
    return c;
}
项目:bridje-framework    文件:HttpBridletResponseImpl.java   
@Override
public HttpCookie addCookie(String name, String value, String path, String domain, int maxAge, boolean secure)
{
    if(cookies == null)
    {
        cookies = new HashMap<>();
    }
    HttpCookieImpl c = new HttpCookieImpl(new DefaultCookie(name, value));
    c.setPath(path);
    c.setDomain(domain);
    c.setMaxAge(maxAge);
    c.setSecure(secure);
    cookies.put(c.getName(), c);
    return c;
}
项目:netty-rest    文件:Response.java   
public Response addCookie(DefaultCookie cookie) {
    if(cookies == null) {
        cookies = Lists.newArrayList();
    }
    cookies.add(cookie);
    return this;
}
项目:netty-rest    文件:Response.java   
public Response addCookie(String name, String value) {
    if(cookies == null) {
        cookies = Lists.newArrayList();
    }
    cookies.add(new DefaultCookie(name, value));
    return this;
}
项目:blade    文件:HttpResponse.java   
@Override
public Response cookie(@NonNull String name, @NonNull String value, int maxAge) {
    Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value);
    nettyCookie.setPath("/");
    nettyCookie.setMaxAge(maxAge);
    this.cookies.add(nettyCookie);
    return this;
}
项目:blade    文件:HttpResponse.java   
@Override
public Response cookie(@NonNull String name, @NonNull String value, int maxAge, boolean secured) {
    Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value);
    nettyCookie.setPath("/");
    nettyCookie.setMaxAge(maxAge);
    nettyCookie.setSecure(secured);
    this.cookies.add(nettyCookie);
    return this;
}
项目:blade    文件:HttpResponse.java   
@Override
public Response cookie(@NonNull String path, @NonNull String name, @NonNull String value, int maxAge, boolean secured) {
    Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value);
    nettyCookie.setMaxAge(maxAge);
    nettyCookie.setSecure(secured);
    nettyCookie.setPath(path);
    this.cookies.add(nettyCookie);
    return this;
}
项目:blade    文件:HttpResponse.java   
@Override
public Response removeCookie(@NonNull String name) {
    Optional<Cookie> cookieOpt = this.cookies.stream().filter(cookie -> cookie.name().equals(name)).findFirst();
    cookieOpt.ifPresent(cookie -> {
        cookie.setValue("");
        cookie.setMaxAge(-1);
    });
    Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, "");
    nettyCookie.setMaxAge(-1);
    this.cookies.add(nettyCookie);
    return this;
}
项目:blade    文件:HttpResponse.java   
public HttpResponse(Response response){
    this.contentType = response.contentType();
    this.statusCode = response.statusCode();
    if(null != response.headers()){
        response.headers().forEach(this.headers::add);
    }
    if(null != response.cookies()){
        response.cookies().forEach( (k,v) -> this.cookies.add(new DefaultCookie(k, v)));
    }
}
项目:glowroot    文件:HttpSessionManager.java   
void deleteSessionCookie(CommonResponse response) throws Exception {
    Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), "");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
}
项目:laputa    文件:HttpClient.java   
private void setCookies(HttpRequest request) {
  if (null == cookies || cookies.isEmpty()) {
    return;
  }
  List<Cookie> cookieList = new ArrayList<>(cookies.size());
  for (Map.Entry<String, String> entry : cookies.entrySet()) {
    cookieList.add(new DefaultCookie(entry.getKey(), entry.getValue()));
  }
  request.headers().set(COOKIE, ClientCookieEncoder.STRICT.encode(cookieList));
}
项目:divconq    文件:WebSession.java   
@Override
public void thawContext(Message result) {
    super.thawContext(result);

    // make sure Session is in Cookies (client handler) too, so that session can work with upload and download
    if (StringUtil.isNotEmpty(this.sessionid)) {
        //Cookie k = new DefaultCookie("SessionId", this.sessionid + "_" + this.sessionKey);
        Cookie k = new DefaultCookie("dcSessionId", this.sessionid + "_XXX");       // TODO resolve this
        this.handler.getCookies().put("dcSessionId", k);
    }
}