本文整理汇总了Java中io.netty.handler.codec.http.cookie.Cookie.setPath方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.setPath方法的具体用法?Java Cookie.setPath怎么用?Java Cookie.setPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.http.cookie.Cookie
的用法示例。
在下文中一共展示了Cookie.setPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSession
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
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;
}
示例2: addCookie
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* 添加一个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);
}
示例3: deleteCookie
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* 删除一个Cookie
* @param request
* @param response
* @param name
* @return
*/
public static boolean deleteCookie(HttpRequest request,HttpResponse response,String name) {
Cookie cookie = getCookie(request,name);
if(cookie!=null){
cookie.setMaxAge(0);
cookie.setPath("/");
setCookie(response,cookie);
return true;
}
return false;
}
示例4: createCookie
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
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;
}
示例5: cookie
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
@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;
}
示例6: deleteSessionCookie
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
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));
}
示例7: writeDownloadHeaders
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
public void writeDownloadHeaders(Channel ch, String name, String mime) {
// Build the response object.
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, this.status);
response.headers().set(Names.CONTENT_TYPE, StringUtil.isNotEmpty(mime) ? mime : MimeUtil.getMimeTypeForFile(name));
if (StringUtil.isEmpty(name))
name = FileUtil.randomFilename("bin");
response.headers().set("Content-Disposition", "attachment; filename=\"" + NetUtil.urlEncodeUTF8(name) + "\"");
Cookie dl = new DefaultCookie("fileDownload", "true");
dl.setPath("/");
response.headers().add(Names.SET_COOKIE, ServerCookieEncoder.STRICT.encode(dl));
// Encode the cookies
for (Cookie c : this.cookies.values())
response.headers().add(Names.SET_COOKIE, ServerCookieEncoder.STRICT.encode(c));
for (Entry<CharSequence, String> h : this.headers.entrySet())
response.headers().set(h.getKey(), h.getValue());
response.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED);
// Write the response.
ch.writeAndFlush(response);
}
示例8: startSession
import io.netty.handler.codec.http.cookie.Cookie; //导入方法依赖的package包/类
/**
* Starts a session and sets the corresponding
* session id as a cookie
*
* @param value session value
*/
public void startSession(S value) {
Cookie cookie = new DefaultCookie(sessions.getCookieKey(), sessions.startSession(value));
cookie.setPath("/");
setCookie(cookie);
}