netty5/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java

121 lines
3.2 KiB
Java
Raw Normal View History

2012-05-31 09:37:27 +02:00
/*
2013-06-04 23:32:11 +02:00
* Copyright 2013 The Netty Project
2012-05-31 09:37:27 +02:00
*
* 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:
*
2012-06-04 22:31:44 +02:00
* http://www.apache.org/licenses/LICENSE-2.0
2012-05-31 09:37:27 +02:00
*
* 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.util.internal.StringUtil;
import java.util.Map;
2012-05-31 09:37:27 +02:00
/**
* The default {@link SpdyHeadersFrame} implementation.
*/
2013-06-04 23:32:11 +02:00
public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame
2012-05-31 09:37:27 +02:00
implements SpdyHeadersFrame {
2013-06-04 23:32:11 +02:00
private boolean invalid;
private boolean truncated;
private final SpdyHeaders headers;
2012-05-31 09:37:27 +02:00
/**
* Creates a new instance.
*
* @param streamId the Stream-ID of this frame
2012-05-31 09:37:27 +02:00
*/
public DefaultSpdyHeadersFrame(int streamId) {
this(streamId, true);
}
/**
* Creates a new instance.
*
* @param streamId the Stream-ID of this frame
* @param validate validate the header names and values when adding them to the {@link SpdyHeaders}
*/
public DefaultSpdyHeadersFrame(int streamId, boolean validate) {
2013-06-04 23:32:11 +02:00
super(streamId);
headers = new DefaultSpdyHeaders(validate);
2012-05-31 09:37:27 +02:00
}
@Override
public SpdyHeadersFrame setStreamId(int streamId) {
2013-06-04 23:32:11 +02:00
super.setStreamId(streamId);
return this;
2012-05-31 09:37:27 +02:00
}
@Override
public SpdyHeadersFrame setLast(boolean last) {
2013-06-04 23:32:11 +02:00
super.setLast(last);
return this;
}
@Override
2013-06-04 23:32:11 +02:00
public boolean isInvalid() {
return invalid;
}
@Override
public SpdyHeadersFrame setInvalid() {
2013-06-04 23:32:11 +02:00
invalid = true;
return this;
2012-05-31 09:37:27 +02:00
}
2013-07-15 08:18:57 +02:00
@Override
public boolean isTruncated() {
return truncated;
}
2013-07-15 08:18:57 +02:00
@Override
public SpdyHeadersFrame setTruncated() {
truncated = true;
return this;
}
@Override
2013-06-04 23:32:11 +02:00
public SpdyHeaders headers() {
return headers;
}
2012-05-31 09:37:27 +02:00
@Override
public String toString() {
StringBuilder buf = new StringBuilder()
.append(StringUtil.simpleClassName(this))
.append("(last: ")
.append(isLast())
.append(')')
.append(StringUtil.NEWLINE)
.append("--> Stream-ID = ")
.append(streamId())
.append(StringUtil.NEWLINE)
.append("--> Headers:")
.append(StringUtil.NEWLINE);
2012-05-31 09:37:27 +02:00
appendHeaders(buf);
// Remove the last newline.
buf.setLength(buf.length() - StringUtil.NEWLINE.length());
return buf.toString();
}
2013-06-04 23:32:11 +02:00
protected void appendHeaders(StringBuilder buf) {
for (Map.Entry<CharSequence, CharSequence> e: headers()) {
2013-06-04 23:32:11 +02:00
buf.append(" ");
buf.append(e.getKey());
buf.append(": ");
buf.append(e.getValue());
buf.append(StringUtil.NEWLINE);
}
}
2012-05-31 09:37:27 +02:00
}