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


Java ClientCookieEncoder类代码示例

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


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

示例1: extractCookies_works_if_cookies_defined_in_headers

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
@Test
public void extractCookies_works_if_cookies_defined_in_headers() {
    // given
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));

    HttpRequest nettyRequestMock = mock(HttpRequest.class);
    doReturn(headers).when(nettyRequestMock).headers();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:18,代码来源:HttpUtilsTest.java

示例2: extractCookies_works_if_cookies_defined_in_trailing_headers

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
@Test
public void extractCookies_works_if_cookies_defined_in_trailing_headers() {
    // given
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    HttpHeaders trailingHeaders = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));

    FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
    doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
    doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:19,代码来源:HttpUtilsTest.java

示例3: extractCookies_handles_cookie_values_leniently

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
@Test
public void extractCookies_handles_cookie_values_leniently() {
    // given
    //these are cookie values seen in the wild...
    Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), "2094%3Az%7C2021%3Ab");
    Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), "geoloc=cc=US,rc=OR,tp=vhigh,tz=PST,la=45.4978,lo=-122.6937,bw=5000");
    Cookie cookie3 = new DefaultCookie(UUID.randomUUID().toString(), "\"dm=n.com&si=27431295-a282-4745-8cd5-542e7fce" +
            "429e&ss=1477551008358&sl=76&tt=437632&obo=12&sh=1477552753923%3D76%3A12%3A437632%2C1477552698670%3D75%3" +
            "A12%3A429879%2C1477552677137%3D74%3A12%3A426596%2C1477552672564%3D73%3A12%3A425585%2C1477552669893%3D72" +
            "%3A12%3A423456&bcn=%2F%2F3408178b.mpstat.us%2F&ld=1477552753923&r=http%3A%2F%2Fwww.nike.com%2Fbe%2Fde_de%" +
            "2F&ul=1477552756811\"");
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2, cookie3));

    HttpRequest nettyRequestMock = mock(HttpRequest.class);
    doReturn(headers).when(nettyRequestMock).headers();

    // when
    Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);

    // then
    assertThat(extractedCookies.contains(cookie1), is(true));
    assertThat(extractedCookies.contains(cookie2), is(true));
    assertThat(extractedCookies.contains(cookie3), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:25,代码来源:HttpUtilsTest.java

示例4: createServerDefault

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的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

示例5: makeEppHttpRequest

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
public static FullHttpRequest makeEppHttpRequest(
    String content,
    String host,
    String path,
    String accessToken,
    String sslClientCertificateHash,
    String serverHostname,
    String clientAddress,
    Cookie... cookies) {
  FullHttpRequest request = makeHttpPostRequest(content, host, path);
  request
      .headers()
      .set(HttpHeaderNames.AUTHORIZATION, "Bearer " + accessToken)
      .set(HttpHeaderNames.CONTENT_TYPE, EPP_CONTENT_TYPE)
      .set(HttpHeaderNames.ACCEPT, EPP_CONTENT_TYPE)
      .set(SSL_CLIENT_CERTIFICATE_HASH_FIELD, sslClientCertificateHash)
      .set(REQUESTED_SERVERNAME_VIA_SNI_FIELD, serverHostname)
      .set(FORWARDED_FOR_FIELD, clientAddress);
  if (cookies.length != 0) {
    request.headers().set(HttpHeaderNames.COOKIE, ClientCookieEncoder.STRICT.encode(cookies));
  }
  return request;
}
 
开发者ID:google,项目名称:nomulus,代码行数:24,代码来源:TestUtils.java

示例6: buildRequestHeaders

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
private void buildRequestHeaders(DefaultFullHttpRequest request) {
    // config request header
    request.headers().set(HttpHeaders.Names.HOST, this.uri.getHost());
    // 添加压缩头
    request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, "gzip, deflate");
    // added user agent
    if (userAgent != null && !userAgent.isEmpty()) request.headers().set(HttpHeaders.Names.USER_AGENT, userAgent);
    else request.headers().remove(HttpHeaders.Names.USER_AGENT);
    // add custom
    if (this.headers != null) {
        for (Entry<String, String> item : this.headers.entrySet()) {
            request.headers().set(item.getKey(), item.getValue());
        }
    }
    // add cookie
    if (this.cookies != null) {
        String cookieValue = ClientCookieEncoder.STRICT.encode(cookies);
        request.headers().set(HttpHeaders.Names.COOKIE, cookieValue);
    }
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:21,代码来源:NHttpRequestParams.java

示例7: start

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
public void start(final HyperSession parent, WritableByteChannel dest, String chanid, Map<String, Cookie> cookies, long size, long offset, final OperationCallback callback) {
   	this.dest = dest;
   	this.cookies = cookies;
   	this.callback = callback;
   	this.size = size;
   	this.sent = offset;
	
   	this.src = this.allocateChannel(parent, callback);
   	
   	if (this.callback.hasErrors()) {
       	callback.complete();
       	return;
   	}
	
	// send a request to get things going
	
	HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/download/" + chanid);
	
	req.headers().set(Names.HOST, parent.getInfo().getHost());
	req.headers().set(Names.USER_AGENT, "DivConq HyperAPI Client 1.0");
	req.headers().set(Names.CONNECTION, HttpHeaders.Values.CLOSE);
       req.headers().set(Names.COOKIE, ClientCookieEncoder.STRICT.encode(this.cookies.values()));
       
       // send request
       this.src.writeAndFlush(req);
}
 
开发者ID:Gadreel,项目名称:divconq,代码行数:27,代码来源:DownloadHandler.java

示例8: setup

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    s = new Server(conf);
    s.run();

    Connector con = mac.getConnector("root", "secret");
    con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));

    this.sessionId = UUID.randomUUID().toString();
    AuthCache.getCache().put(sessionId, token);
    group = new NioEventLoopGroup();
    SslContext ssl = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();

    String cookieVal = ClientCookieEncoder.STRICT.encode(Constants.COOKIE_NAME, sessionId);
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(Names.COOKIE, cookieVal);

    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(LOCATION,
            WebSocketVersion.V13, (String) null, false, headers);
    handler = new ClientHandler(handshaker);
    Bootstrap boot = new Bootstrap();
    boot.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", ssl.newHandler(ch.alloc(), "127.0.0.1", WS_PORT));
            ch.pipeline().addLast(new HttpClientCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(8192));
            ch.pipeline().addLast(handler);
        }
    });
    ch = boot.connect("127.0.0.1", WS_PORT).sync().channel();
    // Wait until handshake is complete
    while (!handshaker.isHandshakeComplete()) {
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
        LOG.debug("Waiting for Handshake to complete");
    }
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:39,代码来源:WebSocketIT.java

示例9: normalize

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
protected void normalize() {
	normalizeParameters();

	String encoded = ClientCookieEncoder.STRICT.encode(cookies);
	if (encoded == null) { return; }

	headers().set(HttpHeaderNames.COOKIE, encoded);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:9,代码来源:HttpRequest.java

示例10: addCookie

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
@Override
public HttpClientRequest addCookie(Cookie cookie) {
	if (!hasSentHeaders()) {
		this.requestHeaders.add(HttpHeaderNames.COOKIE,
				ClientCookieEncoder.STRICT.encode(cookie));
	}
	else {
		throw new IllegalStateException("Status and headers already sent");
	}
	return this;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:12,代码来源:HttpClientOperations.java

示例11: setCookies

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
private void setCookies(HttpRequest request) {
  if (null == cookies || cookies.isEmpty()) {
    return;
  }
  List<Cookie> cookieList = new ArrayList<>(cookies.size());
  for (Map.Entry<String, String> entry : cookies.entrySet()) {
    cookieList.add(new DefaultCookie(entry.getKey(), entry.getValue()));
  }
  request.headers().set(COOKIE, ClientCookieEncoder.STRICT.encode(cookieList));
}
 
开发者ID:orctom,项目名称:laputa,代码行数:11,代码来源:HttpClient.java

示例12: send

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
public void send(Message msg) {
	Logger.debug("Sending message: " + msg);
	
	try {
		if (this.chan != null) {
			if (this.info.getKind() == ConnectorKind.WebSocket)
				this.chan.writeAndFlush(new TextWebSocketFrame(msg.toString()));
			else {
				DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, this.info.getPath());
				
				req.headers().set(Names.HOST, this.info.getHost());
				req.headers().set(Names.USER_AGENT, "DivConq HyperAPI Client 1.0");
				req.headers().set(Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
				req.headers().set(Names.CONTENT_ENCODING, "UTF-8");
				req.headers().set(Names.CONTENT_TYPE, "application/json; charset=utf-8");
	            req.headers().set(Names.COOKIE, ClientCookieEncoder.STRICT.encode(this.cookies.values()));
			    
	            // TODO make more efficient - UTF8 encode directly to buffer
	            ByteBuf buf = Unpooled.copiedBuffer(msg.toString(), CharsetUtil.UTF_8);
	            int clen = buf.readableBytes();
	            req.content().writeBytes(buf);
	            buf.release();
	            
	            // Add 'Content-Length' header only for a keep-alive connection.
	            req.headers().set(Names.CONTENT_LENGTH, clen);
				
				this.chan.writeAndFlush(req);
			}
		}
	}
	catch (Exception x) {
		Logger.error("Send HTTP Message error: " + x);
	}
}
 
开发者ID:Gadreel,项目名称:divconq,代码行数:35,代码来源:ClientHandler.java

示例13: getCookieHeader

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
private String getCookieHeader(HttpRequest request) {
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (org.mockserver.model.Cookie cookie : request.getCookieList()) {
        cookies.add(new DefaultCookie(cookie.getName().getValue(), cookie.getValue().getValue()));
    }
    if (cookies.size() > 0) {
        return " -H '" + COOKIE + ": " + ClientCookieEncoder.LAX.encode(cookies) + "'";
    } else {
        return "";
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:12,代码来源:HttpRequestToCurlSerializer.java

示例14: addCookie

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
private void addCookie(FullHttpRequest request) {
    request.headers().set(Names.COOKIE, ClientCookieEncoder.STRICT.encode(Constants.COOKIE_NAME, cookie));
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:4,代码来源:HttpRequestDecoderTest.java

示例15: netty_helper_constructor_populates_request_info_appropriately

import io.netty.handler.codec.http.cookie.ClientCookieEncoder; //导入依赖的package包/类
@Test
public void netty_helper_constructor_populates_request_info_appropriately() {
    // given
    String uri = "/some/uri/path/%24foobar%26?foo=bar&secondparam=secondvalue";
    Map<String, List<String>> expectedQueryParamMap = new HashMap<>();
    expectedQueryParamMap.put("foo", Arrays.asList("bar"));
    expectedQueryParamMap.put("secondparam", Arrays.asList("secondvalue"));
    HttpMethod method = HttpMethod.PATCH;
    String cookieName = UUID.randomUUID().toString();
    String cookieValue = UUID.randomUUID().toString();
    String content = UUID.randomUUID().toString();
    byte[] contentBytes = content.getBytes();
    Charset contentCharset = CharsetUtil.UTF_8;
    ByteBuf contentByteBuf = Unpooled.copiedBuffer(contentBytes);
    HttpHeaders headers = new DefaultHttpHeaders()
            .add("header1", "val1")
            .add(HttpHeaders.Names.CONTENT_TYPE, contentCharset)
            .add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
            .add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookieName, cookieValue));
    HttpHeaders trailingHeaders = new DefaultHttpHeaders().add("trailingHeader1", "trailingVal1");
    HttpVersion protocolVersion = HttpVersion.HTTP_1_1;

    FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
    doReturn(uri).when(nettyRequestMock).getUri();
    doReturn(method).when(nettyRequestMock).getMethod();
    doReturn(headers).when(nettyRequestMock).headers();
    doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();
    doReturn(contentByteBuf).when(nettyRequestMock).content();
    doReturn(protocolVersion).when(nettyRequestMock).getProtocolVersion();

    // when
    RequestInfoImpl<?> requestInfo = new RequestInfoImpl<>(nettyRequestMock);

    // then
    assertThat("getUri was not the same value sent in", requestInfo.getUri(), is(uri));
    assertThat("getPath did not decode as expected", requestInfo.getPath(), is("/some/uri/path/$foobar&"));
    assertThat(requestInfo.getMethod(), is(method));
    assertThat(requestInfo.getHeaders(), is(headers));
    assertThat(requestInfo.getTrailingHeaders(), is(trailingHeaders));
    assertThat(requestInfo.getQueryParams(), notNullValue());
    assertThat(requestInfo.getQueryParams().parameters(), is(expectedQueryParamMap));
    assertThat(requestInfo.getCookies(), is(Sets.newHashSet(new DefaultCookie(cookieName, cookieValue))));
    assertThat(requestInfo.pathTemplate, nullValue());
    assertThat(requestInfo.pathParams.isEmpty(), is(true));
    assertThat(requestInfo.getRawContentBytes(), is(contentBytes));
    assertThat(requestInfo.getRawContent(), is(content));
    assertThat(requestInfo.content, nullValue());
    assertThat(requestInfo.getContentCharset(), is(contentCharset));
    assertThat(requestInfo.getProtocolVersion(), is(protocolVersion));
    assertThat(requestInfo.isKeepAliveRequested(), is(true));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:52,代码来源:RequestInfoImplTest.java


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