Search in sources :

Example 1 with Cookie

use of com.generallycloud.baseio.codec.http11.future.Cookie in project baseio by generallycloud.

the class TestCookieHeaderServlet method doAccept.

@Override
protected void doAccept(HttpSession session, HttpFuture future) throws Exception {
    System.out.println();
    System.out.println();
    String name = future.getRequestParam("name");
    String value = future.getRequestParam("value");
    if (StringUtil.isNullOrBlank(name)) {
        name = "test8";
    }
    if (StringUtil.isNullOrBlank(value)) {
        value = UUIDGenerator.random();
    }
    String res = "yes server already accept your message :) " + future.getRequestParams();
    Cookie c = new Cookie(name, value);
    c.setComment("comment");
    c.setMaxAge(999999);
    future.addCookie(c);
    future.setResponseHeader(name, value);
    future.write(res);
    session.flush(future);
}
Also used : Cookie(com.generallycloud.baseio.codec.http11.future.Cookie)

Example 2 with Cookie

use of com.generallycloud.baseio.codec.http11.future.Cookie in project baseio by generallycloud.

the class DefaultHttpSessionManager method getHttpSession.

@Override
public HttpSession getHttpSession(HttpContext context, SocketSession ioSession, HttpFuture future) {
    String sessionId = future.getCookie(COOKIE_NAME_SESSIONID);
    if (StringUtil.isNullOrBlank(sessionId)) {
        DefaultHttpSession session = new DefaultHttpSession(context, ioSession);
        sessionId = session.getSessionId();
        Cookie cookie = new Cookie(COOKIE_NAME_SESSIONID, sessionId);
        future.addCookie(cookie);
        this.sessions.put(sessionId, session);
        return session;
    }
    HttpSession session = sessions.get(sessionId);
    if (session == null) {
        session = new DefaultHttpSession(context, ioSession, sessionId);
        this.sessions.put(sessionId, session);
        return session;
    }
    if (!session.isValidate()) {
        sessions.remove(sessionId);
        CloseUtil.close(session.getIoSession());
        return getHttpSession(context, ioSession, future);
    }
    session.active(ioSession);
    return session;
}
Also used : Cookie(com.generallycloud.baseio.codec.http11.future.Cookie)

Example 3 with Cookie

use of com.generallycloud.baseio.codec.http11.future.Cookie in project baseio by generallycloud.

the class ServerHTTPProtocolEncoder method encode.

private void encode(ByteBufAllocator allocator, ServerHttpFuture f, int length, byte[] array) throws IOException {
    ByteBuf buf = allocator.allocate(256);
    try {
        buf.put(PROTOCOL);
        buf.put(f.getStatus().getHeaderBinary());
        buf.put(SERVER_CL);
        buf.put(String.valueOf(length).getBytes());
        buf.put(RN);
        writeHeaders(f, buf);
        List<Cookie> cookieList = f.getCookieList();
        if (cookieList != null) {
            for (Cookie c : cookieList) {
                writeBuf(buf, SET_COOKIE);
                writeBuf(buf, c.toString().getBytes());
                writeBuf(buf, RN);
            }
        }
        writeBuf(buf, RN);
        if (length != 0) {
            writeBuf(buf, array, 0, length);
        }
    } catch (Exception e) {
        ReleaseUtil.release(buf);
        throw e;
    }
    f.setByteBuf(buf.flip());
}
Also used : Cookie(com.generallycloud.baseio.codec.http11.future.Cookie) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) IOException(java.io.IOException)

Example 4 with Cookie

use of com.generallycloud.baseio.codec.http11.future.Cookie in project baseio by generallycloud.

the class ClientHTTPProtocolEncoder method encode.

@Override
public void encode(SocketChannel channel, ChannelFuture future) throws IOException {
    ByteBufAllocator allocator = channel.getByteBufAllocator();
    HttpFuture f = (HttpFuture) future;
    ByteBuf buf = allocator.allocate(256);
    buf.put(f.getMethod().getBytes());
    buf.putByte(SPACE);
    buf.put(getRequestURI(f).getBytes());
    buf.put(PROTOCOL);
    writeHeaders(f, buf);
    List<Cookie> cookieList = f.getCookieList();
    if (cookieList != null && cookieList.size() > 0) {
        buf.put(COOKIE);
        for (Cookie c : cookieList) {
            writeBuf(buf, c.getName().getBytes());
            writeBuf(buf, COLON);
            writeBuf(buf, c.getValue().getBytes());
            writeBuf(buf, SEMICOLON);
        }
        buf.position(buf.position() - 1);
    }
    buf.put(RN);
    future.setByteBuf(buf.flip());
}
Also used : Cookie(com.generallycloud.baseio.codec.http11.future.Cookie) ByteBufAllocator(com.generallycloud.baseio.buffer.ByteBufAllocator) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture)

Aggregations

Cookie (com.generallycloud.baseio.codec.http11.future.Cookie)4 ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)2 ByteBufAllocator (com.generallycloud.baseio.buffer.ByteBufAllocator)1 HttpFuture (com.generallycloud.baseio.codec.http11.future.HttpFuture)1 IOException (java.io.IOException)1