本文整理汇总了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);
}
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
}
示例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;
}
示例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());
}
}
示例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;
}