io.netty.handler.codec.http.cookie.Cookie.name()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中io.netty.handler.codec.http.cookie.Cookie.name()方法的一些代码示例,展示了Cookie.name()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.name()方法的具体详情如下:
包路径:io.netty.handler.codec.http.cookie.Cookie
类名称:Cookie
方法名:name

Cookie.name介绍

[英]Returns the name of this Cookie.
[中]返回此Cookie的名称。

代码示例

代码示例来源:origin: lets-blade/blade

@Override
public Map<String, String> cookies() {
  Map<String, String> map = new HashMap<>(8);
  this.cookies.forEach(cookie -> map.put(cookie.name(), cookie.value()));
  return map;
}

代码示例来源:origin: lets-blade/blade

@Override
public Map<String, String> cookies() {
  Map<String, String> map = new HashMap<>(8);
  this.cookies.forEach(cookie -> map.put(cookie.name(), cookie.value()));
  return map;
}

代码示例来源:origin: lets-blade/blade

@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;
}

代码示例来源:origin: dreamhead/moco

private static ImmutableMap<String, String> doExtractCookies(final String[] cookieStrings) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

    for (String cookie : cookieStrings) {
      Set<Cookie> decodeCookies = ServerCookieDecoder.STRICT.decode(cookie);
      for (Cookie decodeCookie : decodeCookies) {
        builder.put(decodeCookie.name(), decodeCookie.value());
      }
    }

    return builder.build();
  }
}

代码示例来源:origin: lets-blade/blade

@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;
}

代码示例来源:origin: line/armeria

@Get("/welcome")
  public HttpResponse welcome(Cookies cookies) {
    final String name = cookies.stream().filter(c -> "username".equals(c.name()))
                  .map(Cookie::value).findFirst()
                  .orElseThrow(() -> new IllegalArgumentException("No username is found."));
    return HttpResponse.of(HttpStatus.OK, MediaType.HTML_UTF_8,
                "<html><body>Hello, %s! You can see this message " +
                "because you've been authenticated by SSOCircle.</body></html>",
                name);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public MultiValueMap<String, ResponseCookie> getCookies() {
  MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>();
  this.response.cookies().values().stream().flatMap(Collection::stream)
      .forEach(cookie ->
        result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value())
            .domain(cookie.domain())
            .path(cookie.path())
            .maxAge(cookie.maxAge())
            .secure(cookie.isSecure())
            .httpOnly(cookie.isHttpOnly())
            .build()));
  return CollectionUtils.unmodifiableMultiValueMap(result);
}

代码示例来源:origin: org.springframework/spring-web

@Override
public MultiValueMap<String, ResponseCookie> getCookies() {
  MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>();
  this.response.cookies().values().stream().flatMap(Collection::stream)
      .forEach(cookie ->
        result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value())
            .domain(cookie.domain())
            .path(cookie.path())
            .maxAge(cookie.maxAge())
            .secure(cookie.isSecure())
            .httpOnly(cookie.isHttpOnly())
            .build()));
  return CollectionUtils.unmodifiableMultiValueMap(result);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

private void add(String requestDomain, String requestPath, Cookie cookie) {
 AbstractMap.SimpleEntry<String, Boolean> pair = cookieDomain(cookie.domain(), requestDomain);
 String keyDomain = pair.getKey();
 boolean hostOnly = pair.getValue();
 String keyPath = cookiePath(cookie.path(), requestPath);
 CookieKey key = new CookieKey(cookie.name().toLowerCase(), keyDomain, keyPath);
 if (hasCookieExpired(cookie, 0))
  cookieJar.remove(key);
 else
  cookieJar.put(key, new StoredCookie(cookie, hostOnly, cookie.maxAge() != Cookie.UNDEFINED_MAX_AGE));
}

代码示例来源:origin: jamesdbloom/mockserver

private boolean cookieHeaderAlreadyExists(HttpResponse response, Cookie cookieValue) {
  List<String> setCookieHeaders = response.getHeader(SET_COOKIE.toString());
  for (String setCookieHeader : setCookieHeaders) {
    String existingCookieName = ClientCookieDecoder.LAX.decode(setCookieHeader).name();
    String existingCookieValue = ClientCookieDecoder.LAX.decode(setCookieHeader).value();
    if (existingCookieName.equalsIgnoreCase(cookieValue.getName().getValue()) && existingCookieValue.equalsIgnoreCase(cookieValue.getValue().getValue())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: jamesdbloom/mockserver

private boolean cookieHeaderAlreadyExists(HttpResponse response, org.mockserver.model.Cookie cookieValue) {
    List<String> setCookieHeaders = response.getHeader(SET_COOKIE.toString());
    for (String setCookieHeader : setCookieHeaders) {
      String existingCookieName = ClientCookieDecoder.LAX.decode(setCookieHeader).name();
      String existingCookieValue = ClientCookieDecoder.LAX.decode(setCookieHeader).value();
      if (existingCookieName.equalsIgnoreCase(cookieValue.getName().getValue()) && existingCookieValue.equalsIgnoreCase(cookieValue.getValue().getValue())) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: wildfly/wildfly

private void encode(StringBuilder buf, Cookie c) {
    final String name = c.name();
    final String value = c.value() != null ? c.value() : "";

    validateCookie(name, value);

    if (c.wrap()) {
      addQuoted(buf, name, value);
    } else {
      add(buf, name, value);
    }
  }
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_set_and_recognize_cookie() throws IOException {
  runWithConfiguration("cookie.json");
  Cookie decodeCookie = getCookie("/cookie");
  assertThat(decodeCookie.name(), is("login"));
  assertThat(decodeCookie.value(), is("true"));
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_set_and_recognize_cookie_with_domain() throws IOException {
  runWithConfiguration("cookie.json");
  Cookie decodeCookie = getCookie("/cookie-with-domain");
  assertThat(decodeCookie.name(), is("login"));
  assertThat(decodeCookie.value(), is("true"));
  assertThat(decodeCookie.domain(), is("github.com"));
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_set_and_recognize_cookie_with_secure() throws IOException {
  runWithConfiguration("cookie.json");
  Cookie decodeCookie = getCookie("/cookie-with-secure");
  assertThat(decodeCookie.name(), is("login"));
  assertThat(decodeCookie.value(), is("true"));
  assertThat(decodeCookie.isSecure(), is(true));
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_set_and_recognize_cookie_with_path() throws IOException {
  runWithConfiguration("cookie.json");
  Cookie decodeCookie = getCookie("/cookie-with-path");
  assertThat(decodeCookie.name(), is("login"));
  assertThat(decodeCookie.value(), is("true"));
  assertThat(decodeCookie.path(), is("/"));
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_set_and_recognize_cookie_with_max_age() throws IOException {
  runWithConfiguration("cookie.json");
  Cookie decodeCookie = getCookie("/cookie-with-max-age");
  assertThat(decodeCookie.name(), is("login"));
  assertThat(decodeCookie.value(), is("true"));
  assertThat(decodeCookie.maxAge(), is(3600L));
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_set_and_recognize_cookie_with_http_only() throws IOException {
  runWithConfiguration("cookie.json");
  Cookie decodeCookie = getCookie("/cookie-with-http-only");
  assertThat(decodeCookie.name(), is("login"));
  assertThat(decodeCookie.value(), is("true"));
  assertThat(decodeCookie.isHttpOnly(), is(true));
}

代码示例来源:origin: lets-blade/blade

/**
 * Parse netty cookie to {@link Cookie}.
 *
 * @param nettyCookie netty raw cookie instance
 */
private void parseCookie(io.netty.handler.codec.http.cookie.Cookie nettyCookie) {
  var cookie = new Cookie();
  cookie.name(nettyCookie.name());
  cookie.value(nettyCookie.value());
  cookie.httpOnly(nettyCookie.isHttpOnly());
  cookie.path(nettyCookie.path());
  cookie.domain(nettyCookie.domain());
  cookie.maxAge(nettyCookie.maxAge());
  this.cookies.put(cookie.name(), cookie);
}

代码示例来源:origin: lets-blade/blade

/**
 * Parse netty cookie to {@link Cookie}.
 *
 * @param nettyCookie netty raw cookie instance
 */
private void parseCookie(io.netty.handler.codec.http.cookie.Cookie nettyCookie) {
  var cookie = new Cookie();
  cookie.name(nettyCookie.name());
  cookie.value(nettyCookie.value());
  cookie.httpOnly(nettyCookie.isHttpOnly());
  cookie.path(nettyCookie.path());
  cookie.domain(nettyCookie.domain());
  cookie.maxAge(nettyCookie.maxAge());
  this.cookies.put(cookie.name(), cookie);
}

相关文章