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


Java HttpMessage.headers方法代码示例

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


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

示例1: addHeaders

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
/**
 *  Extract headers from {@link io.netty.handler.codec.http.HttpMessage} and put in temporary
 *  headers. Headers are stored as multi-map because given the same key, it can have more than
 *  one values.
 *  @param httpMessage netty http message
 * */
public void addHeaders(HttpMessage httpMessage) {
  if (httpMessage.headers() == null) {
    return;
  }
  for (String name : httpMessage.headers().names()) {
    for (String value : httpMessage.headers().getAll(name)) {
      if (!_headers.containsEntry(name, value)) {
        _headers.put(name, value);
      }
    }
  }
}
 
开发者ID:linkedin,项目名称:flashback,代码行数:19,代码来源:RecordedHttpMessageBuilder.java

示例2: setTransferEncoding

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
private static void setTransferEncoding(HttpMessage out) {
    final io.netty.handler.codec.http.HttpHeaders outHeaders = out.headers();
    final long contentLength = HttpUtil.getContentLength(out, -1L);
    if (contentLength < 0) {
        // Use chunked encoding.
        outHeaders.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
        outHeaders.remove(HttpHeaderNames.CONTENT_LENGTH);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:10,代码来源:Http1ObjectEncoder.java

示例3: getHeaders

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
public static Headers getHeaders(HttpMessage message) {
    List<Header> headers = new LinkedList<>();
    if (message.headers() != null) {
        for (Map.Entry<String, String> k : message.headers().entries()) {
            headers.add(new Header(k.getKey(), k.getValue()));
        }
    }
    return new Headers(headers);
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:10,代码来源:Util.java

示例4: before0

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
private void before0(Trace trace, Object target, Object[] args) {
    if (!trace.canSampled()) {
        HttpMessage httpMessage = (HttpMessage) args[1];
        HttpHeaders headers = httpMessage.headers();
        addHeaderIfNotExist(headers, Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    doInBeforeTrace(recorder, trace, target, args);
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:11,代码来源:HttpEncoderInterceptor.java

示例5: doInBeforeTrace

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
protected void doInBeforeTrace(SpanEventRecorder recorder, Trace trace, Object target, Object[] args) {
    // generate next trace id.
    final TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(NettyConstants.SERVICE_TYPE_CODEC_HTTP);

    ChannelHandlerContext channelHandlerContext = (ChannelHandlerContext) args[0];
    Channel channel = channelHandlerContext.channel();
    final String endpoint = NettyUtils.getEndPoint(channel.remoteAddress());
    recorder.recordDestinationId(endpoint);

    HttpMessage httpMessage = (HttpMessage) args[1];
    HttpHeaders headers = httpMessage.headers();

    addHeaderIfNotExist(headers, Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
    addHeaderIfNotExist(headers, Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));

    addHeaderIfNotExist(headers, Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));

    addHeaderIfNotExist(headers, Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
    addHeaderIfNotExist(headers, Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
    addHeaderIfNotExist(headers, Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));

    addHeaderIfNotExist(headers, Header.HTTP_HOST.toString(), endpoint);

    if (httpMessage instanceof HttpRequest) {
        recorder.recordAttribute(AnnotationKey.HTTP_URL, ((HttpRequest) httpMessage).getUri());
    }
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:30,代码来源:HttpEncoderInterceptor.java

示例6: validate

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
private boolean validate(Object[] args) {
    if (args.length != 3) {
        return false;
    }

    if (!(args[0] instanceof ChannelHandlerContext)) {
        return false;
    }
    ChannelHandlerContext channelHandlerContext = (ChannelHandlerContext) args[0];
    Channel channel = channelHandlerContext.channel();
    if (channel == null) {
        return false;
    }

    if (!(args[1] instanceof HttpMessage)) {
        return false;
    }
    HttpMessage httpMessage = (HttpMessage) args[1];
    if (httpMessage.headers() == null) {
        return false;
    }
    if (!(args[1] instanceof AsyncContextAccessor)) {
        return false;
    }
    if (!(args[1] instanceof AsyncStartFlagFieldAccessor)) {
        return false;
    }

    return true;
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:31,代码来源:HttpEncoderInterceptor.java

示例7: setHeaders

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
public static void setHeaders(HttpMessage message, Headers headers) {
    HttpHeaders httpHeaders = message.headers();
    for (Header header : headers.getAll()) {
        httpHeaders.add(header.getName(), header.getValue());
    }
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:7,代码来源:Util.java

示例8: createSynStreamFrame

import io.netty.handler.codec.http.HttpMessage; //导入方法依赖的package包/类
private SpdySynStreamFrame createSynStreamFrame(HttpMessage httpMessage)
        throws Exception {
    // Get the Stream-ID, Associated-To-Stream-ID, Priority, URL, and scheme from the headers
    int streamID = SpdyHttpHeaders.getStreamId(httpMessage);
    int associatedToStreamId = SpdyHttpHeaders.getAssociatedToStreamId(httpMessage);
    byte priority = SpdyHttpHeaders.getPriority(httpMessage);
    String URL = SpdyHttpHeaders.getUrl(httpMessage);
    String scheme = SpdyHttpHeaders.getScheme(httpMessage);
    SpdyHttpHeaders.removeStreamId(httpMessage);
    SpdyHttpHeaders.removeAssociatedToStreamId(httpMessage);
    SpdyHttpHeaders.removePriority(httpMessage);
    SpdyHttpHeaders.removeUrl(httpMessage);
    SpdyHttpHeaders.removeScheme(httpMessage);

    // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
    // headers are not valid and MUST not be sent.
    httpMessage.headers().remove(HttpHeaders.Names.CONNECTION);
    httpMessage.headers().remove("Keep-Alive");
    httpMessage.headers().remove("Proxy-Connection");
    httpMessage.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);

    SpdySynStreamFrame spdySynStreamFrame =
            new DefaultSpdySynStreamFrame(streamID, associatedToStreamId, priority);

    // Unfold the first line of the message into name/value pairs
    if (httpMessage instanceof FullHttpRequest) {
        HttpRequest httpRequest = (HttpRequest) httpMessage;
        SpdyHeaders.setMethod(spdyVersion, spdySynStreamFrame, httpRequest.getMethod());
        SpdyHeaders.setUrl(spdyVersion, spdySynStreamFrame, httpRequest.getUri());
        SpdyHeaders.setVersion(spdyVersion, spdySynStreamFrame, httpMessage.getProtocolVersion());
    }
    if (httpMessage instanceof HttpResponse) {
        HttpResponse httpResponse = (HttpResponse) httpMessage;
        SpdyHeaders.setStatus(spdyVersion, spdySynStreamFrame, httpResponse.getStatus());
        SpdyHeaders.setUrl(spdyVersion, spdySynStreamFrame, URL);
        SpdyHeaders.setVersion(spdyVersion, spdySynStreamFrame, httpMessage.getProtocolVersion());
        spdySynStreamFrame.setUnidirectional(true);
    }

    // Replace the HTTP host header with the SPDY host header
    if (spdyVersion >= 3) {
        String host = HttpHeaders.getHost(httpMessage);
        httpMessage.headers().remove(HttpHeaders.Names.HOST);
        SpdyHeaders.setHost(spdySynStreamFrame, host);
    }

    // Set the SPDY scheme header
    if (scheme == null) {
        scheme = "https";
    }
    SpdyHeaders.setScheme(spdyVersion, spdySynStreamFrame, scheme);

    // Transfer the remaining HTTP headers
    for (Map.Entry<String, String> entry: httpMessage.headers()) {
        spdySynStreamFrame.headers().add(entry.getKey(), entry.getValue());
    }
    currentStreamId = spdySynStreamFrame.getStreamId();
    spdySynStreamFrame.setLast(isLast(httpMessage));

    return spdySynStreamFrame;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:62,代码来源:SpdyHttpEncoder.java


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