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


Java HttpMessage类代码示例

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


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

示例1: mock

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Test
public void argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo_only_returns_true_for_HttpRequest_or_LastHttpContent() {
    // given
    Object httpRequestMsg = mock(HttpRequest.class);
    Object lastHttpContentMsg = mock(LastHttpContent.class);
    Object httpMessageMsg = mock(HttpMessage.class);

    // expect
    assertThat(handlerSpy.argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(
        DO_CHANNEL_READ, ctxMock, httpRequestMsg, null)
    ).isTrue();
    assertThat(handlerSpy.argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(
        DO_CHANNEL_READ, ctxMock, lastHttpContentMsg, null)
    ).isTrue();
    assertThat(handlerSpy.argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(
        DO_CHANNEL_READ, ctxMock, httpMessageMsg, null)
    ).isFalse();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:19,代码来源:RequestFilterHandlerTest.java

示例2: handleUploadMessage

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
private void handleUploadMessage(HttpMessage httpMsg, Message uploadMessage) throws IOException{
	if (httpMsg instanceof HttpContent) { 
           HttpContent chunk = (HttpContent) httpMsg;
           decoder.offer(chunk); 
           try {
               while (decoder.hasNext()) {
                   InterfaceHttpData data = decoder.next();
                   if (data != null) {
                       try { 
                       	handleUploadFile(data, uploadMessage);
                       } finally {
                           data.release();
                       }
                   }
               }
           } catch (EndOfDataDecoderException e1) { 
           	//ignore
           }
           
           if (chunk instanceof LastHttpContent) {  
           	resetUpload();
           }
       }
}
 
开发者ID:rushmore,项目名称:zbus,代码行数:25,代码来源:MessageCodec.java

示例3: isContentAlwaysEmpty

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Override
protected boolean isContentAlwaysEmpty(HttpMessage httpMessage) {
    if (httpMessage instanceof HttpResponse) {
        // Identify our current request
        identifyCurrentRequest();
    }

    // The current HTTP Request can be null when this proxy is
    // negotiating a CONNECT request with a chained proxy 
    // while it is running as a MITM. Since the response to a
    // CONNECT request does not have any content, we return true.
    if(currentHttpRequest == null) {
        return true;
    } else {
        return HttpMethod.HEAD.equals(currentHttpRequest.getMethod()) ?
                true : super.isContentAlwaysEmpty(httpMessage);
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:19,代码来源:ProxyToServerConnection.java

示例4: addVia

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
/**
 * Adds the Via header to specify that the message has passed through the proxy. The specified alias will be
 * appended to the Via header line. The alias may be the hostname of the machine proxying the request, or a
 * pseudonym. From RFC 7230, section 5.7.1:
 * <pre>
     The received-by portion of the field value is normally the host and
     optional port number of a recipient server or client that
     subsequently forwarded the message.  However, if the real host is
     considered to be sensitive information, a sender MAY replace it with
     a pseudonym.
 * </pre>
 *
 * 
 * @param httpMessage HTTP message to add the Via header to
 * @param alias the alias to provide in the Via header for this proxy
 */
public static void addVia(HttpMessage httpMessage, String alias) {
    String newViaHeader =  new StringBuilder()
            .append(httpMessage.getProtocolVersion().majorVersion())
            .append('.')
            .append(httpMessage.getProtocolVersion().minorVersion())
            .append(' ')
            .append(alias)
            .toString();

    final List<String> vias;
    if (httpMessage.headers().contains(HttpHeaders.Names.VIA)) {
        List<String> existingViaHeaders = httpMessage.headers().getAll(HttpHeaders.Names.VIA);
        vias = new ArrayList<String>(existingViaHeaders);
        vias.add(newViaHeader);
    } else {
        vias = Collections.singletonList(newViaHeader);
    }

    httpMessage.headers().set(HttpHeaders.Names.VIA, vias);
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:37,代码来源:ProxyUtils.java

示例5: testAddNewViaHeaderToExistingViaHeader

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Test
public void testAddNewViaHeaderToExistingViaHeader() {
    String hostname = "hostname";

    HttpMessage httpMessage = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/endpoint");
    httpMessage.headers().add(HttpHeaders.Names.VIA, "1.1 otherproxy");
    ProxyUtils.addVia(httpMessage, hostname);

    List<String> viaHeaders = httpMessage.headers().getAll(HttpHeaders.Names.VIA);
    assertThat(viaHeaders, hasSize(2));

    assertEquals("1.1 otherproxy", viaHeaders.get(0));

    String expectedViaHeader = "1.1 " + hostname;
    assertEquals(expectedViaHeader, viaHeaders.get(1));
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:17,代码来源:ProxyUtilsTest.java

示例6: addVia

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
/**
 * Adds the Via header to specify that the message has passed through the
 * proxy.
 * 
 * @param msg
 *            The HTTP message.
 */
public static void addVia(final HttpMessage msg) {
    final StringBuilder sb = new StringBuilder();
    sb.append(msg.getProtocolVersion().majorVersion());
    sb.append(".");
    sb.append(msg.getProtocolVersion().minorVersion());
    sb.append(".");
    sb.append(hostName);
    final List<String> vias;
    if (msg.headers().contains(HttpHeaders.Names.VIA)) {
        vias = msg.headers().getAll(HttpHeaders.Names.VIA);
        vias.add(sb.toString());
    } else {
        vias = Arrays.asList(sb.toString());
    }
    msg.headers().set(HttpHeaders.Names.VIA, vias);
}
 
开发者ID:Elitward,项目名称:LittleProxy,代码行数:24,代码来源:ProxyUtils.java

示例7: channelRead

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object obj) {
    final ChannelPipeline pipeline = ctx.pipeline();
    if (obj instanceof HttpMessage && !WebSocketHandlerUtil.isWebSocket((HttpMessage)obj)) {
        if (null != pipeline.get(PIPELINE_AUTHENTICATOR)) {
            pipeline.remove(PIPELINE_REQUEST_HANDLER);
            final ChannelHandler authenticator = pipeline.get(PIPELINE_AUTHENTICATOR);
            pipeline.remove(PIPELINE_AUTHENTICATOR);
            pipeline.addAfter(PIPELINE_HTTP_RESPONSE_ENCODER, PIPELINE_AUTHENTICATOR, authenticator);
            pipeline.addAfter(PIPELINE_AUTHENTICATOR, PIPELINE_REQUEST_HANDLER, this.httpGremlinEndpointHandler);
        } else {
            pipeline.remove(PIPELINE_REQUEST_HANDLER);
            pipeline.addAfter(PIPELINE_HTTP_RESPONSE_ENCODER, PIPELINE_REQUEST_HANDLER, this.httpGremlinEndpointHandler);
        }
    }
    ctx.fireChannelRead(obj);
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:18,代码来源:WsAndHttpChannelizerHandler.java

示例8: convertToHttp

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
/**
 * Convert the OData Response to Netty Response
 * @param response
 * @param odResponse
 */
static void convertToHttp(final HttpResponse response, final ODataResponse odResponse) {
   response.setStatus(HttpResponseStatus.valueOf(odResponse.getStatusCode()));

   for (Entry<String, List<String>> entry : odResponse.getAllHeaders().entrySet()) {
     for (String headerValue : entry.getValue()) {
       ((HttpMessage)response).headers().add(entry.getKey(), headerValue);
     }
   }

   if (odResponse.getContent() != null) {
     copyContent(odResponse.getContent(), response);
   } else if (odResponse.getODataContent() != null) {
     writeContent(odResponse, response);
   }
 }
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:21,代码来源:ODataNettyHandlerImpl.java

示例9: resolveClientIpByRemoteAddressHeader

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
public static SocketAddress resolveClientIpByRemoteAddressHeader(HttpMessage message, String headerName) {
  SocketAddress clientIp = null;
  if (headerName != null && !headerName.trim().isEmpty()) {
    String ip = null;
    try {
      ip = message.headers().get(headerName);
      if (ip != null) {
        ip = ip.split(",")[0]; // to handle multiple proxies case (e.g. X-Forwarded-For: client, proxy1, proxy2)
        clientIp = new InetSocketAddress(InetAddress.getByName(ip), 0);
      }
    } catch (Exception e) {
      log.warn("Failed to parse IP address: {} from http header: {}", ip, headerName);
    }
  }
  return clientIp;
}
 
开发者ID:scalecube,项目名称:socketio,代码行数:17,代码来源:PipelineUtils.java

示例10: write

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    LOGGER.info("[Client ({})] => [Server ({})] : {}",
                connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
                msg);
    if (msg instanceof FullHttpRequest) {
        HttpMessage httpMessage = (HttpRequest) msg;
        httpMessage.headers().add(ExtensionHeaderNames.SCHEME.text(), "https");
    } else if (msg instanceof HttpObject) {
        throw new IllegalStateException("Cannot handle message: " + msg.getClass());
    }

    ctx.writeAndFlush(msg, promise);
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:15,代码来源:Http2BackendHandler.java

示例11: channelRead_does_nothing_if_msg_is_not_HttpRequest_or_LastHttpContent

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Test
public void channelRead_does_nothing_if_msg_is_not_HttpRequest_or_LastHttpContent() throws Exception {
    // given
    HttpMessage ignoredMsgMock = mock(HttpMessage.class);

    // when
    handler.channelRead(ctxMock, ignoredMsgMock);

    // then
    verify(ctxMock).fireChannelRead(ignoredMsgMock); // the normal continuation behavior from the super class.
    verifyNoMoreInteractions(ctxMock); // nothing else should have happened related to the ctx.
    verifyZeroInteractions(stateMock);
    verifyZeroInteractions(metricsListenerMock);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:15,代码来源:RequestStateCleanerHandlerTest.java

示例12: channelRead

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object e) {
    if (e instanceof HttpMessage) {
        HttpMessage m = (HttpMessage) e;
        // for test there is no Content-Encoding header so just hard
        // coding value
        // for verification
        m.headers().set("X-Original-Content-Encoding", "<original encoding>");
    }
    ctx.fireChannelRead(e);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:12,代码来源:EventPipelineTest.java

示例13: getCharsetFromMessage

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
/**
 * Derives the charset from the Content-Type header in the HttpMessage. If the Content-Type header is not present or does not contain
 * a character set, this method returns the ISO-8859-1 character set. See {@link BrowserMobHttpUtil#readCharsetInContentTypeHeader(String)}
 * for more details.
 *
 * @param httpMessage HTTP message to extract charset from
 * @return the charset associated with the HTTP message, or the default charset if none is present
 * @throws UnsupportedCharsetException if there is a charset specified in the content-type header, but it is not supported
 */
public static Charset getCharsetFromMessage(HttpMessage httpMessage) throws UnsupportedCharsetException {
    String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE);

    Charset charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentTypeHeader);
    if (charset == null) {
        return BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET;
    }

    return charset;
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:20,代码来源:HttpObjectUtil.java

示例14: send

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Override
public Mono<Void> send() {
	if (markSentHeaderAndBody()) {
		HttpMessage request = newFullEmptyBodyMessage();
		return FutureMono.deferFuture(() -> channel().writeAndFlush(request));
	}
	else {
		return Mono.empty();
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:11,代码来源:HttpClientOperations.java

示例15: newFullEmptyBodyMessage

import io.netty.handler.codec.http.HttpMessage; //导入依赖的package包/类
@Override
protected HttpMessage newFullEmptyBodyMessage() {
	HttpRequest request = new DefaultFullHttpRequest(version(), method(), uri());

	request.headers()
	       .set(requestHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING)
	                          .setInt(HttpHeaderNames.CONTENT_LENGTH, 0));
	return request;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:10,代码来源:HttpClientOperations.java


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