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


Java ServerCookieDecoder类代码示例

本文整理汇总了Java中io.netty.handler.codec.http.cookie.ServerCookieDecoder的典型用法代码示例。如果您正苦于以下问题:Java ServerCookieDecoder类的具体用法?Java ServerCookieDecoder怎么用?Java ServerCookieDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getUser

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
/**
 * 从Http Cookie中获取用户Id
 * 
 * @param data
 * @return
 */
public static final PushUser getUser(HandshakeData data) {
    String _cookie = data.getSingleHeader(HttpHeaders.Names.COOKIE);
    if (_cookie != null) {
        Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(_cookie);
        for (Cookie cookie : cookies) {
            if (TokenManager.LOGIN_COOKIE_NAME.equals(cookie.name())) {
                String value = cookie.value();
                if (value != null) {
                    return getUserIdFromCookie(value);
                }
            }
        }
    }
    return null;
}
 
开发者ID:bridgeli,项目名称:netty-socketio-demo,代码行数:22,代码来源:CookieUserAuthorizationListener.java

示例2: getSessionId

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public static String getSessionId(FullHttpRequest msg, boolean anonymousAccessAllowed) {
    final StringBuilder buf = new StringBuilder();
    msg.headers().getAll(Names.COOKIE).forEach(h -> {
        ServerCookieDecoder.STRICT.decode(h).forEach(c -> {
            if (c.name().equals(Constants.COOKIE_NAME)) {
                if (buf.length() == 0) {
                    buf.append(c.value());
                }
            }
        });
    });
    String sessionId = buf.toString();
    if (sessionId.length() == 0 && anonymousAccessAllowed) {
        sessionId = NO_AUTHORIZATIONS;
    } else if (sessionId.length() == 0) {
        sessionId = null;
    }
    return sessionId;
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:20,代码来源:HttpRequestDecoder.java

示例3: createServerDefault

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public static HttpResponse createServerDefault(String requestCookie) {
	HttpResponse ret = new HttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.buffer());

	ret.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=UTF-8");

	if (requestCookie == null) { return ret; }

	Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(requestCookie);
	if (cookies.isEmpty()) { return ret; }

	// Reset the cookies if necessary.
	for (Cookie cookie : cookies) {
		ret.headers().add(HttpHeaderNames.SET_COOKIE, ClientCookieEncoder.STRICT.encode(cookie));
	}

	return ret;
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:18,代码来源:HttpResponse.java

示例4: captureRequestCookies

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
protected void captureRequestCookies(HttpRequest httpRequest) {
    Log.e("InnerHandle", "captureRequestCookies " + harEntry.getId());
    String cookieHeader = httpRequest.headers().get(HttpHeaders.Names.COOKIE);
    if (cookieHeader == null) {
        return;
    }

    Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader);

    for (Cookie cookie : cookies) {
        HarCookie harCookie = new HarCookie();

        harCookie.setName(cookie.name());
        harCookie.setValue(cookie.value());

        harRequest.getRequest().getCookies().add(harCookie);
        harRequest.addHeader(cookie.name(), cookie.value());
    }
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:20,代码来源:HarCaptureFilter.java

示例5: getUserFromCookie

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public User getUserFromCookie(FullHttpRequest request) {
    String cookieString = request.headers().get(HttpHeaderNames.COOKIE);

    if (cookieString != null) {
        Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieString);
        if (!cookies.isEmpty()) {
            for (Cookie cookie : cookies) {
                if (isValid(cookie)) {
                    String token = cookie.value();
                    return httpSession.get(token);
                }
            }
        }
    }

    return null;
}
 
开发者ID:blynkkk,项目名称:blynk-server,代码行数:18,代码来源:SessionDao.java

示例6: getCookies

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
/**
 * 获取HttpRequest中的Cookies
 * @param request
 * @return
 */
public static Set<Cookie> getCookies(HttpRequest request){
    Set<Cookie> cookies;
    String value = request.headers().get(HttpHeaderNames.COOKIE);
    if (value == null) {
        cookies = Collections.emptySet();
    } else {
        cookies = ServerCookieDecoder.STRICT.decode(value);
    }
    return cookies;
}
 
开发者ID:all4you,项目名称:redant,代码行数:16,代码来源:CookieHelper.java

示例7: addCookies

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
private void addCookies(HttpResponse resp) {
    if (transport.resetCookies) {
        String cookieString = nettyRequest.headers().get(HttpHeaders.Names.COOKIE);
        if (cookieString != null) {
            Set<io.netty.handler.codec.http.cookie.Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieString);
            if (!cookies.isEmpty()) {
                // Reset the cookies if necessary.
                resp.headers().set(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookies));
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:Netty4HttpChannel.java

示例8: getCookies

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public static final Collection<Cookie> getCookies(String name, HttpRequest request) {
    String cookieString = request.headers().get(COOKIE);
    if (cookieString != null) {
        List<Cookie> foundCookie = new ArrayList<Cookie>();
        // 不验证name 和 value
        Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieString);
        for (Cookie cookie : cookies) {
            if (cookie.name().equals(name))
                foundCookie.add(cookie);
        }

        return foundCookie;
    }
    return null;
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:16,代码来源:Utils.java

示例9: handle

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
@Override
public void handle(ServerWebSocket serverWebSocket) {
    String basePath = Optional.ofNullable(mountPoint)
        .map(m -> m.substring(0, m.lastIndexOf('/')) )
        .orElse("");

    if (!serverWebSocket.path().startsWith(basePath + "/PUSH")) {
        serverWebSocket.reject();
    }
    String cookieHeader = serverWebSocket.headers().get(COOKIE);

    if (cookieHeader != null) {
        Optional<String> sessionId = ServerCookieDecoder.STRICT.decode(cookieHeader).stream()
            .filter(cookie -> cookieName.equals(cookie.name()))
            .findFirst().map(Cookie::value);
        if (sessionId.isPresent()) {
            sessionId.ifPresent(sid -> sessionStore.get(sid, event -> {
                    Session session = null;
                    if (event.succeeded()) {
                        session = event.result();
                    }
                    next.accept(serverWebSocket, session);
                }
            ));
            return;
        }
    }
    next.accept(serverWebSocket, null);
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:30,代码来源:WebsocketSessionHandler.java

示例10: extractCookies

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public static Set<Cookie> extractCookies(HttpRequest request) {
    Set<Cookie> cookies = new HashSet<>();

    HttpHeaders trailingHeaders = extractTrailingHeadersIfPossible(request);

    String cookieString = request.headers().get(COOKIE);
    if (cookieString == null && trailingHeaders != null)
        cookieString = trailingHeaders.get(COOKIE);

    if (cookieString != null)
        cookies.addAll(ServerCookieDecoder.LAX.decode(cookieString));

    return cookies;
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:15,代码来源:HttpUtils.java

示例11: writeResponse

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
    // Decide whether to close the connection or not.
    boolean keepAlive = HttpUtil.isKeepAlive(request);
    // Build the response object.
    FullHttpResponse response = new DefaultFullHttpResponse(
            HTTP_1_1, currentObj.decoderResult().isSuccess()? OK : BAD_REQUEST,
            Unpooled.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));

    response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");

    if (keepAlive) {
        // Add 'Content-Length' header only for a keep-alive connection.
        response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
        // Add keep alive header as per:
        // - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
        response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }

    // Encode the cookie.
    String cookieString = request.headers().get(HttpHeaderNames.COOKIE);
    if (cookieString != null) {
        Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieString);
        if (!cookies.isEmpty()) {
            // Reset the cookies if necessary.
            for (Cookie cookie: cookies) {
                response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
            }
        }
    } else {
        // Browser sent no cookie.  Add some.
        response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode("key1", "value1"));
        response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode("key2", "value2"));
    }

    // Write the response.
    ctx.write(response);

    return keepAlive;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:40,代码来源:HttpSnoopServerHandler.java

示例12: parseCookies

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public Set<Cookie> parseCookies(String cookiesHeader)
{
    Set<Cookie> cookies;
    if (cookiesHeader == null)
    {
        cookies = Collections.emptySet();
    }
    else
    {
        cookies = ServerCookieDecoder.STRICT.decode(cookiesHeader);
    }
    return cookies;
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:14,代码来源:HttpServerChannelHandler.java

示例13: WrappedRequest

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
public WrappedRequest(FullHttpRequest req, Map<String, String> params, SessionStore<S> sessions) {
	this.req = req;
	this.params = params;
	this.query = new QueryStringDecoder(req.getUri());
	this.cookies = new HashMap<>();
	this.sessions = sessions;
	
	{
		getHeader(Names.COOKIE).ifPresent(header -> {
			for (Cookie c : ServerCookieDecoder.LAX.decode(header)) {
				cookies.put(c.name(), c);
			}
		});
	}
}
 
开发者ID:lukasdietrich,项目名称:lambdatra,代码行数:16,代码来源:WrappedRequest.java

示例14: init

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
private void init(FullHttpRequest fullHttpRequest) {
    // headers
    HttpHeaders httpHeaders = fullHttpRequest.headers();
    if (httpHeaders.size() > 0) {
        this.headers = new HashMap<>(httpHeaders.size());
        httpHeaders.forEach((header) -> headers.put(header.getKey(), header.getValue()));
    } else {
        this.headers = new HashMap<>();
    }

    // body content
    this.body = fullHttpRequest.content().copy();

    // request query parameters
    Map<String, List<String>> parameters = new QueryStringDecoder(fullHttpRequest.uri(), CharsetUtil.UTF_8).parameters();
    if (null != parameters) {
        this.parameters = new HashMap<>();
        this.parameters.putAll(parameters);
    }

    if (!HttpConst.METHOD_GET.equals(fullHttpRequest.method().name())) {
        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(HTTP_DATA_FACTORY, fullHttpRequest);
        decoder.getBodyHttpDatas().forEach(this::parseData);
    }

    // cookies
    String cookie = header(HttpConst.COOKIE_STRING);
    cookie = cookie.length() > 0 ? cookie : header(HttpConst.COOKIE_STRING.toLowerCase());
    if (StringKit.isNotBlank(cookie)) {
        ServerCookieDecoder.LAX.decode(cookie).forEach(this::parseCookie);
    }
}
 
开发者ID:lets-blade,项目名称:blade,代码行数:33,代码来源:HttpRequest.java

示例15: getSessionId

import io.netty.handler.codec.http.cookie.ServerCookieDecoder; //导入依赖的package包/类
@Nullable
String getSessionId(CommonRequest request) throws Exception {
    String cookieHeader = request.getHeader(HttpHeaderNames.COOKIE);
    if (cookieHeader == null) {
        return null;
    }
    Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(cookieHeader);
    for (Cookie cookie : cookies) {
        if (cookie.name().equals(configRepository.getWebConfig().sessionCookieName())) {
            return cookie.value();
        }
    }
    return null;
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:15,代码来源:HttpSessionManager.java


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