1 /*
2 * Copyright 2009 Red Hat, Inc.
3 *
4 * Red Hat licenses this file to you under the Apache License, version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package org.jboss.netty.handler.codec.http2;
17
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.jboss.netty.buffer.ChannelBuffer;
24 import org.jboss.netty.buffer.ChannelBuffers;
25 import org.jboss.netty.channel.ChannelPipeline;
26
27 /**
28 * An HTTP chunk which is used for HTTP chunked transfer-encoding.
29 * {@link HttpMessageDecoder} generates {@link HttpChunk} after
30 * {@link HttpMessage} when the content is large or the encoding of the content
31 * is 'chunked. If you prefer not to receive {@link HttpChunk} in your handler,
32 * please {@link HttpChunkAggregator} after {@link HttpMessageDecoder} in the
33 * {@link ChannelPipeline}.
34 *
35 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
36 * @author <a href="http://gleamynode.net/">Trustin Lee</a>
37 * @version $Rev: 1191 $, $Date: 2012-05-10 20:38:47 +0200 (jeu., 10 mai 2012) $
38 *
39 * @apiviz.landmark
40 */
41 public interface HttpChunk {
42
43 /**
44 * The 'end of content' marker in chunked encoding.
45 */
46 HttpChunkTrailer LAST_CHUNK = new HttpChunkTrailer() {
47 public ChannelBuffer getContent() {
48 return ChannelBuffers.EMPTY_BUFFER;
49 }
50
51 public void setContent(ChannelBuffer content) {
52 throw new IllegalStateException("read-only");
53 }
54
55 public boolean isLast() {
56 return true;
57 }
58
59 public void addHeader(String name, Object value) {
60 throw new IllegalStateException("read-only");
61 }
62
63 public void clearHeaders() {
64 // NOOP
65 }
66
67 public boolean containsHeader(String name) {
68 return false;
69 }
70
71 public String getHeader(String name) {
72 return null;
73 }
74
75 public Set<String> getHeaderNames() {
76 return Collections.emptySet();
77 }
78
79 public List<String> getHeaders(String name) {
80 return Collections.emptyList();
81 }
82
83 public List<Map.Entry<String, String>> getHeaders() {
84 return Collections.emptyList();
85 }
86
87 public void removeHeader(String name) {
88 // NOOP
89 }
90
91 public void setHeader(String name, Object value) {
92 throw new IllegalStateException("read-only");
93 }
94
95 public void setHeader(String name, Iterable<?> values) {
96 throw new IllegalStateException("read-only");
97 }
98 };
99
100 /**
101 * Returns {@code true} if and only if this chunk is the 'end of content'
102 * marker.
103 */
104 boolean isLast();
105
106 /**
107 * Returns the content of this chunk. If this is the 'end of content'
108 * marker, {@link ChannelBuffers#EMPTY_BUFFER} will be returned.
109 */
110 ChannelBuffer getContent();
111
112 /**
113 * Sets the content of this chunk. If an empty buffer is specified,
114 * this chunk becomes the 'end of content' marker.
115 */
116 void setContent(ChannelBuffer content);
117 }