本文整理了Java中io.netty.handler.codec.http.cookie.Cookie.setDomain()
方法的一些代码示例,展示了Cookie.setDomain()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.setDomain()
方法的具体详情如下:
包路径:io.netty.handler.codec.http.cookie.Cookie
类名称:Cookie
方法名:setDomain
[英]Sets the domain of this Cookie.
[中]设置此Cookie的域。
代码示例来源:origin: dreamhead/moco
@Override
public void visit(final Cookie cookie) {
cookie.setDomain(this.domain);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public Cookie domain(String domain) {
nettyCookie.setDomain(domain);
return this;
}
代码示例来源:origin: line/armeria
CookieBasedSsoHandler(String cookieName, String cookieValue) {
requireNonNull(cookieName, "cookieName");
requireNonNull(cookieValue, "cookieValue");
final Cookie cookie = new DefaultCookie(cookieName, cookieValue);
cookie.setDomain(spHostname);
cookie.setPath("/");
cookie.setHttpOnly(true);
setCookie = ServerCookieEncoder.STRICT.encode(cookie);
}
代码示例来源:origin: line/armeria
/**
* Invoked when the SAML authentication process is finished and a user is authenticated. You can get
* information about the authenticated user from the {@link Response}, especially his or her login name.
* In this example, an email address is used as a login name. The login name is transferred to a web
* browser via {@code Set-Cookie} header.
*/
@Override
public HttpResponse loginSucceeded(ServiceRequestContext ctx, AggregatedHttpMessage req,
MessageContext<Response> message, @Nullable String sessionIndex,
@Nullable String relayState) {
final String username =
getNameId(message.getMessage(), SamlNameIdFormat.EMAIL).map(NameIDType::getValue)
.orElse(null);
if (username == null) {
return HttpResponse.of(HttpStatus.UNAUTHORIZED, MediaType.HTML_UTF_8,
"<html><body>Username is not found.</body></html>");
}
logger.info("{} user '{}' has been logged in.", ctx, username);
final Cookie cookie = new DefaultCookie("username", username);
cookie.setHttpOnly(true);
cookie.setDomain("localhost");
cookie.setMaxAge(60);
cookie.setPath("/");
return HttpResponse.of(
HttpHeaders.of(HttpStatus.OK)
.contentType(MediaType.HTML_UTF_8)
.add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie)),
HttpData.ofUtf8("<html><body onLoad=\"window.location.href='/welcome'\"></body></html>"));
}
代码示例来源:origin: lets-blade/blade
@Override
public Response cookie(@NonNull com.blade.mvc.http.Cookie cookie) {
Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(cookie.name(), cookie.value());
if (cookie.domain() != null) {
nettyCookie.setDomain(cookie.domain());
}
if (cookie.maxAge() > 0) {
nettyCookie.setMaxAge(cookie.maxAge());
}
nettyCookie.setPath(cookie.path());
nettyCookie.setHttpOnly(cookie.httpOnly());
nettyCookie.setSecure(cookie.secure());
this.cookies.add(nettyCookie);
return this;
}
代码示例来源:origin: lets-blade/blade
@Override
public Response cookie(@NonNull com.blade.mvc.http.Cookie cookie) {
Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(cookie.name(), cookie.value());
if (cookie.domain() != null) {
nettyCookie.setDomain(cookie.domain());
}
if (cookie.maxAge() > 0) {
nettyCookie.setMaxAge(cookie.maxAge());
}
nettyCookie.setPath(cookie.path());
nettyCookie.setHttpOnly(cookie.httpOnly());
nettyCookie.setSecure(cookie.secure());
this.cookies.add(nettyCookie);
return this;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void testAddOrReplaceCookies() {
RequestBuilder requestBuilder = new RequestBuilder();
Cookie cookie = new DefaultCookie("name", "value");
cookie.setDomain("google.com");
cookie.setPath("/");
cookie.setMaxAge(1000);
cookie.setSecure(true);
cookie.setHttpOnly(true);
requestBuilder.addOrReplaceCookie(cookie);
assertEquals(requestBuilder.cookies.size(), 1, "cookies size should be 1 after adding one cookie");
assertEquals(requestBuilder.cookies.get(0), cookie, "cookie does not match");
Cookie cookie2 = new DefaultCookie("name", "value");
cookie2.setDomain("google2.com");
cookie2.setPath("/path");
cookie2.setMaxAge(1001);
cookie2.setSecure(false);
cookie2.setHttpOnly(false);
requestBuilder.addOrReplaceCookie(cookie2);
assertEquals(requestBuilder.cookies.size(), 1, "cookies size should remain 1 as we just replaced a cookie with same name");
assertEquals(requestBuilder.cookies.get(0), cookie2, "cookie does not match");
Cookie cookie3 = new DefaultCookie("name2", "value");
cookie3.setDomain("google.com");
cookie3.setPath("/");
cookie3.setMaxAge(1000);
cookie3.setSecure(true);
cookie3.setHttpOnly(true);
requestBuilder.addOrReplaceCookie(cookie3);
assertEquals(requestBuilder.cookies.size(), 2, "cookie size must be 2 after adding 1 more cookie i.e. cookie3");
}
代码示例来源:origin: vert-x3/vertx-web
@Override
public Cookie setDomain(final String domain) {
nettyCookie.setDomain(domain);
this.changed = true;
return this;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void applyCookies() {
for (String name : getCookies().keySet()) {
for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
}
if (httpCookie.getDomain() != null) {
cookie.setDomain(httpCookie.getDomain());
}
if (httpCookie.getPath() != null) {
cookie.setPath(httpCookie.getPath());
}
cookie.setSecure(httpCookie.isSecure());
cookie.setHttpOnly(httpCookie.isHttpOnly());
this.response.addCookie(cookie);
}
}
}
代码示例来源:origin: org.springframework/spring-web
@Override
protected void applyCookies() {
for (String name : getCookies().keySet()) {
for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
}
if (httpCookie.getDomain() != null) {
cookie.setDomain(httpCookie.getDomain());
}
if (httpCookie.getPath() != null) {
cookie.setPath(httpCookie.getPath());
}
cookie.setSecure(httpCookie.isSecure());
cookie.setHttpOnly(httpCookie.isHttpOnly());
this.response.addCookie(cookie);
}
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void getWithCookies() throws Throwable {
withClient().run(client ->
withServer(server).run(server -> {
final Cookie coo = new DefaultCookie("foo", "value");
coo.setDomain("/");
coo.setPath("/");
server.enqueueEcho();
client.prepareGet(getTargetUrl())
.addCookie(coo)
.execute(new AsyncCompletionHandlerAdapter() {
@Override
public Response onCompleted(Response response) {
assertEquals(response.getStatusCode(), 200);
List<Cookie> cookies = response.getCookies();
assertEquals(cookies.size(), 1);
assertEquals(cookies.get(0).toString(), "foo=value");
return response;
}
}).get(TIMEOUT, SECONDS);
}));
}
代码示例来源:origin: io.vertx/vertx-web
@Override
public Cookie setDomain(final String domain) {
nettyCookie.setDomain(domain);
this.changed = true;
return this;
}
代码示例来源:origin: javagossip/dorado
@Override
public void setDomain(String domain) {
cookie.setDomain(domain);
}
代码示例来源:origin: pmlopes/yoke
@Override
public void setDomain(final String domain) {
nettyCookie.setDomain(domain);
}
代码示例来源:origin: looly/loServer
/**
* 设定返回给客户端的Cookie
*
* @param name cookie名
* @param value cookie值
* @param maxAgeInSeconds -1: 关闭浏览器清除Cookie. 0: 立即清除Cookie. n>0 : Cookie存在的秒数.
* @param path Cookie的有效路径
* @param domain the Cookie可见的域,依据 RFC 2109 标准
* @return 自己
*/
public Response addCookie(String name, String value, int maxAgeInSeconds, String path, String domain) {
Cookie cookie = new DefaultCookie(name, value);
if (domain != null) {
cookie.setDomain(domain);
}
cookie.setMaxAge(maxAgeInSeconds);
cookie.setPath(path);
return addCookie(cookie);
}
代码示例来源:origin: com.bladejava/blade-mvc
@Override
public Response cookie(@NonNull com.blade.mvc.http.Cookie cookie) {
Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(cookie.name(), cookie.value());
if (cookie.domain() != null) {
nettyCookie.setDomain(cookie.domain());
}
if (cookie.maxAge() > 0) {
nettyCookie.setMaxAge(cookie.maxAge());
}
nettyCookie.setPath(cookie.path());
nettyCookie.setHttpOnly(cookie.httpOnly());
nettyCookie.setSecure(cookie.secure());
this.cookies.add(nettyCookie);
return this;
}
代码示例来源:origin: co.paralleluniverse/comsat-actors-netty
static io.netty.handler.codec.http.cookie.Cookie getNettyCookie(Cookie c) {
io.netty.handler.codec.http.cookie.Cookie ret = new io.netty.handler.codec.http.cookie.DefaultCookie(c.getName(), c.getValue());
ret.setDomain(c.getDomain());
ret.setHttpOnly(c.isHttpOnly());
ret.setMaxAge(c.getMaxAge());
ret.setPath(c.getPath());
ret.setSecure(c.isSecure());
return ret;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
@Override
protected void applyCookies() {
for (String name : getCookies().keySet()) {
for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
}
if (httpCookie.getDomain() != null) {
cookie.setDomain(httpCookie.getDomain());
}
if (httpCookie.getPath() != null) {
cookie.setPath(httpCookie.getPath());
}
cookie.setSecure(httpCookie.isSecure());
cookie.setHttpOnly(httpCookie.isHttpOnly());
this.response.addCookie(cookie);
}
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override
protected void applyCookies() {
for (String name : getCookies().keySet()) {
for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
}
if (httpCookie.getDomain() != null) {
cookie.setDomain(httpCookie.getDomain());
}
if (httpCookie.getPath() != null) {
cookie.setPath(httpCookie.getPath());
}
cookie.setSecure(httpCookie.isSecure());
cookie.setHttpOnly(httpCookie.isHttpOnly());
this.response.addCookie(cookie);
}
}
}
代码示例来源:origin: io.vertx/vertx-web-client
c.setDomain("vertx.io");
store.put(c);
c.setDomain("www.vertx.io");
c.setPath("/web-client");
store.put(c);
c.setDomain("vertx.io");
c.setSecure(true);
store.put(c);
c.setDomain("www.vertx.io");
store.put(c);
c.setDomain("www.vertx.io");
c.setPath("/web-client");
store.put(c);
内容来源于网络,如有侵权,请联系作者删除!