View Javadoc

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.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   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
29   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
30   * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
31   */
32  public class DefaultHttpChunkTrailer implements HttpChunkTrailer {
33  
34      private final HttpHeaders headers = new HttpHeaders() {
35          @Override
36          void validateHeaderName(String name) {
37              super.validateHeaderName(name);
38              if (name.equalsIgnoreCase(HttpHeaders.Names.CONTENT_LENGTH) ||
39                  name.equalsIgnoreCase(HttpHeaders.Names.TRANSFER_ENCODING) ||
40                  name.equalsIgnoreCase(HttpHeaders.Names.TRAILER)) {
41                  throw new IllegalArgumentException(
42                          "prohibited trailing header: " + name);
43              }
44          }
45      };
46  
47      public boolean isLast() {
48          return true;
49      }
50  
51      public void addHeader(final String name, final Object value) {
52          headers.addHeader(name, value);
53      }
54  
55      public void setHeader(final String name, final Object value) {
56          headers.setHeader(name, value);
57      }
58  
59      public void setHeader(final String name, final Iterable<?> values) {
60          headers.setHeader(name, values);
61      }
62  
63      public void removeHeader(final String name) {
64          headers.removeHeader(name);
65      }
66  
67      public void clearHeaders() {
68          headers.clearHeaders();
69      }
70  
71      public String getHeader(final String name) {
72          return headers.getHeader(name);
73      }
74  
75      public List<String> getHeaders(final String name) {
76          return headers.getHeaders(name);
77      }
78  
79      public List<Map.Entry<String, String>> getHeaders() {
80          return headers.getHeaders();
81      }
82  
83      public boolean containsHeader(final String name) {
84          return headers.containsHeader(name);
85      }
86  
87      public Set<String> getHeaderNames() {
88          return headers.getHeaderNames();
89      }
90  
91      public ChannelBuffer getContent() {
92          return ChannelBuffers.EMPTY_BUFFER;
93      }
94  
95      public void setContent(ChannelBuffer content) {
96          throw new IllegalStateException("read-only");
97      }
98  }