View Javadoc

1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the 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.http;
17  
18  import java.util.List;
19  import java.util.Map;
20  import java.util.Set;
21  
22  import org.jboss.netty.buffer.ChannelBuffer;
23  import org.jboss.netty.buffer.ChannelBuffers;
24  
25  /**
26   * The default {@link HttpChunkTrailer} implementation.
27   */
28  public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
29  
30      private final HttpHeaders headers = new HttpHeaders() {
31          @Override
32          void validateHeaderName(String name) {
33              super.validateHeaderName(name);
34              if (name.equalsIgnoreCase(HttpHeaders.Names.CONTENT_LENGTH) ||
35                  name.equalsIgnoreCase(HttpHeaders.Names.TRANSFER_ENCODING) ||
36                  name.equalsIgnoreCase(HttpHeaders.Names.TRAILER)) {
37                  throw new IllegalArgumentException(
38                          "prohibited trailing header: " + name);
39              }
40          }
41      };
42  
43      public boolean isLast() {
44          return true;
45      }
46  
47      public void addHeader(final String name, final Object value) {
48          headers.addHeader(name, value);
49      }
50  
51      public void setHeader(final String name, final Object value) {
52          headers.setHeader(name, value);
53      }
54  
55      public void setHeader(final String name, final Iterable<?> values) {
56          headers.setHeader(name, values);
57      }
58  
59      public void removeHeader(final String name) {
60          headers.removeHeader(name);
61      }
62  
63      public void clearHeaders() {
64          headers.clearHeaders();
65      }
66  
67      public String getHeader(final String name) {
68          return headers.getHeader(name);
69      }
70  
71      public List<String> getHeaders(final String name) {
72          return headers.getHeaders(name);
73      }
74  
75      public List<Map.Entry<String, String>> getHeaders() {
76          return headers.getHeaders();
77      }
78  
79      public boolean containsHeader(final String name) {
80          return headers.containsHeader(name);
81      }
82  
83      public Set<String> getHeaderNames() {
84          return headers.getHeaderNames();
85      }
86  
87      public ChannelBuffer getContent() {
88          return ChannelBuffers.EMPTY_BUFFER;
89      }
90  
91      public void setContent(ChannelBuffer content) {
92          throw new IllegalStateException("read-only");
93      }
94  }