當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders.add方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.HttpHeaders.add方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.add方法的具體用法?Java HttpHeaders.add怎麽用?Java HttpHeaders.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testConvert

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void testConvert() throws IOException {
    Response responseMock = mock(Response.class);

    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(TEST_KEY_A, TEST_VALUE_B);
    headers.add(TEST_KEY_C, TEST_VALUE_D);

    when(responseMock.getHeaders()).thenReturn(headers);
    when(responseMock.getStatusCode()).thenReturn(STATUS_CODE);
    when(responseMock.getStatusText()).thenReturn(STATUS_TEXT);
    when(responseMock.getResponseBodyAsStream()).thenReturn(
            new ByteArrayInputStream(ENCODED_BODY.getBytes(StandardCharsets.UTF_8))
    );

    BiFunction<Response, Request, HttpResponse> converter = new AsyncResponseConverter();
    HttpResponse awsResponse = converter.apply(responseMock, null);

    assertThat(awsResponse.getHeaders().get(TEST_KEY_A)).isEqualTo(TEST_VALUE_B);
    assertThat(awsResponse.getHeaders().get(TEST_KEY_C)).isEqualTo(TEST_VALUE_D);
    assertThat(awsResponse.getStatusCode()).isEqualTo(STATUS_CODE);
    assertThat(awsResponse.getStatusText()).isEqualTo(STATUS_TEXT);
    assertThat(new BufferedReader(new InputStreamReader(awsResponse.getContent())).readLine())
            .isEqualTo(ENCODED_BODY);
}
 
開發者ID:Bandwidth,項目名稱:async-sqs,代碼行數:26,代碼來源:AsyncResponseConverterTest.java

示例2: test_validateSecureRequestForEndpoint_adds_security_context_to_request

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void test_validateSecureRequestForEndpoint_adds_security_context_to_request() {
    final RequestInfo<Void> requestInfo = mock(RequestInfo.class);
    when(requestInfo.getUri()).thenReturn("https://localhost");
    final HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(CmsRequestSecurityValidator.HEADER_X_VAULT_TOKEN, vaultToken);
    when(requestInfo.getHeaders()).thenReturn(httpHeaders);

    final Map<String, String> meta = Maps.newHashMap();
    meta.put(VaultAuthPrincipal.METADATA_KEY_IS_ADMIN, Boolean.TRUE.toString());
    meta.put(VaultAuthPrincipal.METADATA_KEY_USERNAME, "username");
    meta.put(VaultAuthPrincipal.METADATA_KEY_GROUPS, "group1,group2");
    final VaultClientTokenResponse clientTokenResponse = new VaultClientTokenResponse()
            .setId(vaultToken)
            .setMeta(meta);
    when(vaultAdminClient.lookupToken(vaultToken)).thenReturn(clientTokenResponse);

    subject.validateSecureRequestForEndpoint(requestInfo, securedEndpoint);

    verify(requestInfo).addRequestAttribute(eq(SECURITY_CONTEXT_ATTR_KEY), any(SecurityContext.class));
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:22,代碼來源:CmsRequestSecurityValidatorTest.java

示例3: execute_throws_api_error_when_bad_auth_header

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void execute_throws_api_error_when_bad_auth_header() {
    final RequestInfo<Void> requestInfo = mock(RequestInfo.class);
    final HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(HttpHeaders.Names.AUTHORIZATION, invalidAuthorizationHeader);
    when(requestInfo.getHeaders()).thenReturn(httpHeaders);

    try {
        final CompletableFuture<ResponseInfo<AuthResponse>> completableFuture =
                subject.execute(requestInfo, executor, null);
        completableFuture.join();
        fail("Expected exception not thrown.");
    } catch (CompletionException cex) {
        assertThat(cex.getCause()).isInstanceOf(ApiException.class);
    }
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:17,代碼來源:AuthenticateUserTest.java

示例4: writeResponseHead

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Override
public void writeResponseHead(Response restletResponse) throws IOException {
    setNettyResponse(new DefaultHttpResponse(HTTP_1_1, new HttpResponseStatus(getStatusCode(), getReasonPhrase())));
    HttpHeaders headers = getNettyResponse().headers();

    // this.response.clear();
    for (Header header : getResponseHeaders()) {
        headers.add(header.getName(), header.getValue());
    }

    // Decide whether to close the connection or not.
    if (isKeepAlive()) {
        headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        getNettyChannel().write(getNettyResponse());
    } else {
        getNettyChannel().writeAndFlush(getNettyResponse()).addListener(ChannelFutureListener.CLOSE);
    }
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:19,代碼來源:NettyServerCall.java

示例5: getHeaderMapDelegatesToRequestInfoAndCachesResult

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void getHeaderMapDelegatesToRequestInfoAndCachesResult() {
    Map<String, List<String>> expectedHeaderMap = new TreeMap<>(MapBuilder.<String, List<String>>builder()
                                                                          .put("header1", Arrays.asList("h1val1"))
                                                                          .put("header2", Arrays.asList("h2val1", "h2val2"))
                                                                          .build());

    HttpHeaders nettyHeaders = new DefaultHttpHeaders();
    for (Map.Entry<String, List<String>> headerEntry : expectedHeaderMap.entrySet()) {
        nettyHeaders.add(headerEntry.getKey(), headerEntry.getValue());
    }
    setFieldOnRequestInfo("headers", nettyHeaders);
    Map<String, List<String>> actualHeaderMap = adapter.getHeadersMap();
    assertThat(actualHeaderMap, is(expectedHeaderMap));
    assertThat(adapter.getHeadersMap(), sameInstance(actualHeaderMap));
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:17,代碼來源:RequestInfoForLoggingRiposteAdapterTest.java

示例6: addHeader

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
/**
 * Adding header to Http Carbon message
 *
 * @param httpCarbonMessage
 */
public static void addHeader(HTTPCarbonMessage httpCarbonMessage) {
    String headerName = "";
    String headerValue = "";

    HttpHeaders httpHeaders = httpCarbonMessage.getHeaders();
    httpHeaders.add(headerName, headerValue);

    if (log.isDebugEnabled()) {
        log.debug("Add " + headerName + " to header with value: " + headerValue);
    }
}
 
開發者ID:wso2-extensions,項目名稱:siddhi-io-http,代碼行數:17,代碼來源:HttpIoUtil.java

示例7: setup

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的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

示例8: test_validateSecureRequestForEndpoint_throws_error_when_vault_server_exception_caught

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test(expected = ApiException.class)
public void test_validateSecureRequestForEndpoint_throws_error_when_vault_server_exception_caught() {
    final RequestInfo<?> requestInfo = mock(RequestInfo.class);
    final HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(CmsRequestSecurityValidator.HEADER_X_VAULT_TOKEN, vaultToken);
    when(requestInfo.getHeaders()).thenReturn(httpHeaders);

    when(vaultAdminClient.lookupToken(vaultToken)).thenThrow(new VaultServerException(1, Lists.newArrayList()));

    subject.validateSecureRequestForEndpoint(requestInfo, securedEndpoint);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:12,代碼來源:CmsRequestSecurityValidatorTest.java

示例9: test_validateSecureRequestForEndpoint_throws_error_when_vault_client_exception_caught

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test(expected = ApiException.class)
public void test_validateSecureRequestForEndpoint_throws_error_when_vault_client_exception_caught() {
    final RequestInfo<?> requestInfo = mock(RequestInfo.class);
    final HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(CmsRequestSecurityValidator.HEADER_X_VAULT_TOKEN, vaultToken);
    when(requestInfo.getHeaders()).thenReturn(httpHeaders);

    when(vaultAdminClient.lookupToken(vaultToken)).thenThrow(new VaultClientException("Failure"));

    subject.validateSecureRequestForEndpoint(requestInfo, securedEndpoint);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:12,代碼來源:CmsRequestSecurityValidatorTest.java

示例10: test_getClientVersion

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void test_getClientVersion() {
    String fakeVersion = "fake/1.2.3";
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(CerberusHttpHeaders.HEADER_X_CERBERUS_CLIENT, fakeVersion);
    RequestInfo request = mock(RequestInfo.class);
    when(request.getHeaders()).thenReturn(headers);

    Assert.assertEquals(fakeVersion, CerberusHttpHeaders.getClientVersion(request));
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:11,代碼來源:CerberusHttpHeadersTest.java

示例11: test_getXForwardedClientIp_with_three

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void test_getXForwardedClientIp_with_three() {
    String value = "ip1, ip2, ip3";
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(CerberusHttpHeaders.HEADER_X_FORWARDED_FOR, value);
    RequestInfo request = mock(RequestInfo.class);
    when(request.getHeaders()).thenReturn(headers);

    Assert.assertEquals("ip1", CerberusHttpHeaders.getXForwardedClientIp(request));
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:11,代碼來源:CerberusHttpHeadersTest.java

示例12: test_getXForwardedClientIp_with_one

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void test_getXForwardedClientIp_with_one() {
    String value = "ip1";
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(CerberusHttpHeaders.HEADER_X_FORWARDED_FOR, value);
    RequestInfo request = mock(RequestInfo.class);
    when(request.getHeaders()).thenReturn(headers);

    Assert.assertEquals("ip1", CerberusHttpHeaders.getXForwardedClientIp(request));
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:11,代碼來源:CerberusHttpHeadersTest.java

示例13: execute_returns_vault_auth_response

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void execute_returns_vault_auth_response() {
    final AuthResponse authResponse = new AuthResponse();
    final RequestInfo<Void> requestInfo = mock(RequestInfo.class);
    final HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(HttpHeaders.Names.AUTHORIZATION, validAuthorizationHeader);
    when(requestInfo.getHeaders()).thenReturn(httpHeaders);
    when(authenticationService.authenticate(any(UserCredentials.class))).thenReturn(authResponse);

    final CompletableFuture<ResponseInfo<AuthResponse>> completableFuture =
            subject.execute(requestInfo, executor, null);
    final ResponseInfo<AuthResponse> responseInfo = completableFuture.join();

    assertThat(responseInfo.getContentForFullResponse()).isEqualTo(authResponse);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:16,代碼來源:AuthenticateUserTest.java

示例14: testOnHeadersReceivedContentLengthMinus

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void testOnHeadersReceivedContentLengthMinus() throws Exception {
    ResumableAsyncHandler handler = new ResumableAsyncHandler();
    HttpHeaders responseHeaders = new DefaultHttpHeaders();
    responseHeaders.add(HttpHeaders.Names.CONTENT_LENGTH, -1);
    HttpResponseHeaders headers = new HttpResponseHeaders(responseHeaders);
    State status = handler.onHeadersReceived(headers);
    assertEquals(status, AsyncHandler.State.ABORT, "State should be ABORT for content length -1");
}
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:10,代碼來源:ResumableAsyncHandlerTest.java

示例15: copyHeaders

import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
static void copyHeaders(HttpServletRequest request, HttpHeaders to) {
    Enumeration<String> headers = request.getHeaderNames();
    while(headers.hasMoreElements()) {
        String header = headers.nextElement();
        Iterable<String> iter = () -> Iterators.forEnumeration(request.getHeaders(header));
        to.add(header, iter);
    }
}
 
開發者ID:codeabovelab,項目名稱:haven-platform,代碼行數:9,代碼來源:Utils.java


注:本文中的io.netty.handler.codec.http.HttpHeaders.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。