Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.UnsupportedMessageTypeException;
import io.netty.handler.codec.http.FullHttpMessage;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.AsciiString;
import io.netty.util.internal.ObjectUtil;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* Encodes {@link HttpRequest}s, {@link HttpResponse}s, and {@link HttpContent}s
* into {@link SpdySynStreamFrame}s and {@link SpdySynReplyFrame}s.
*
*
Request Annotations
*
* SPDY specific headers must be added to {@link HttpRequest}s:
*
*
*
Header Name
Header Value
*
*
*
{@code "X-SPDY-Stream-ID"}
*
The Stream-ID for this request.
* Stream-IDs must be odd, positive integers, and must increase monotonically.
*
*
*
{@code "X-SPDY-Priority"}
*
The priority value for this request.
* The priority should be between 0 and 7 inclusive.
* 0 represents the highest priority and 7 represents the lowest.
* This header is optional and defaults to 0.
*
*
*
*
Response Annotations
*
* SPDY specific headers must be added to {@link HttpResponse}s:
*
*
*
Header Name
Header Value
*
*
*
{@code "X-SPDY-Stream-ID"}
*
The Stream-ID of the request corresponding to this response.
*
*
*
*
Pushed Resource Annotations
*
* SPDY specific headers must be added to pushed {@link HttpRequest}s:
*
*
*
Header Name
Header Value
*
*
*
{@code "X-SPDY-Stream-ID"}
*
The Stream-ID for this resource.
* Stream-IDs must be even, positive integers, and must increase monotonically.
*
*
*
{@code "X-SPDY-Associated-To-Stream-ID"}
*
The Stream-ID of the request that initiated this pushed resource.
*
*
*
{@code "X-SPDY-Priority"}
*
The priority value for this resource.
* The priority should be between 0 and 7 inclusive.
* 0 represents the highest priority and 7 represents the lowest.
* This header is optional and defaults to 0.
*
*
*
*
Required Annotations
*
* SPDY requires that all Requests and Pushed Resources contain
* an HTTP "Host" header.
*
*
Optional Annotations
*
* Requests and Pushed Resources must contain a SPDY scheme header.
* This can be set via the {@code "X-SPDY-Scheme"} header but otherwise
* defaults to "https" as that is the most common SPDY deployment.
*
*
Chunked Content
*
* This encoder associates all {@link HttpContent}s that it receives
* with the most recently received 'chunked' {@link HttpRequest}
* or {@link HttpResponse}.
*
*
Pushed Resources
*
* All pushed resources should be sent before sending the response
* that corresponds to the initial request.
*/
public class SpdyHttpEncoder extends MessageToMessageEncoder {
private int currentStreamId;
private final boolean validateHeaders;
private final boolean headersToLowerCase;
/**
* Creates a new instance.
*
* @param version the protocol version
*/
public SpdyHttpEncoder(SpdyVersion version) {
this(version, true, true);
}
/**
* Creates a new instance.
*
* @param version the protocol version
* @param headersToLowerCase convert header names to lowercase. In a controlled environment,
* one can disable the conversion.
* @param validateHeaders validate the header names and values when adding them to the {@link SpdyHeaders}
*/
public SpdyHttpEncoder(SpdyVersion version, boolean headersToLowerCase, boolean validateHeaders) {
ObjectUtil.checkNotNull(version, "version");
this.headersToLowerCase = headersToLowerCase;
this.validateHeaders = validateHeaders;
}
@Override
protected void encode(ChannelHandlerContext ctx, HttpObject msg, List