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.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 * An HTTP message which provides common properties for {@link HttpRequest} and 27 * {@link HttpResponse}. 28 * 29 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a> 30 * @author Andy Taylor (andy.taylor@jboss.org) 31 * @author <a href="http://gleamynode.net/">Trustin Lee</a> 32 * @version $Rev: 619 $, $Date: 2010-11-11 20:30:06 +0100 (jeu., 11 nov. 2010) $ 33 * 34 * @see HttpHeaders 35 * 36 * @apiviz.landmark 37 * @apiviz.has org.jboss.netty.handler.codec.http2.HttpChunk oneway - - is followed by 38 */ 39 public interface HttpMessage { 40 41 /** 42 * Returns the header value with the specified header name. If there are 43 * more than one header value for the specified header name, the first 44 * value is returned. 45 * 46 * @return the header value or {@code null} if there is no such header 47 * 48 */ 49 String getHeader(String name); 50 51 /** 52 * Returns the header values with the specified header name. 53 * 54 * @return the {@link List} of header values. An empty list if there is no 55 * such header. 56 */ 57 List<String> getHeaders(String name); 58 59 /** 60 * Returns the all header names and values that this message contains. 61 * 62 * @return the {@link List} of the header name-value pairs. An empty list 63 * if there is no header in this message. 64 */ 65 List<Map.Entry<String, String>> getHeaders(); 66 67 /** 68 * Returns {@code true} if and only if there is a header with the specified 69 * header name. 70 */ 71 boolean containsHeader(String name); 72 73 /** 74 * Returns the {@link Set} of all header names that this message contains. 75 */ 76 Set<String> getHeaderNames(); 77 78 /** 79 * Returns the protocol version of this message. 80 */ 81 HttpVersion getProtocolVersion(); 82 83 /** 84 * Sets the protocol version of this message. 85 */ 86 void setProtocolVersion(HttpVersion version); 87 88 /** 89 * Returns the content of this message. If there is no content or 90 * {@link #isChunked()} returns {@code true}, an 91 * {@link ChannelBuffers#EMPTY_BUFFER} is returned. 92 */ 93 ChannelBuffer getContent(); 94 95 /** 96 * Sets the content of this message. If {@code null} is specified, 97 * the content of this message will be set to {@link ChannelBuffers#EMPTY_BUFFER}. 98 */ 99 void setContent(ChannelBuffer content); 100 101 /** 102 * Adds a new header with the specified name and value. 103 */ 104 void addHeader(String name, Object value); 105 106 /** 107 * Sets a new header with the specified name and value. If there is an 108 * existing header with the same name, the existing header is removed. 109 */ 110 void setHeader(String name, Object value); 111 112 /** 113 * Sets a new header with the specified name and values. If there is an 114 * existing header with the same name, the existing header is removed. 115 */ 116 void setHeader(String name, Iterable<?> values); 117 118 /** 119 * Removes the header with the specified name. 120 */ 121 void removeHeader(String name); 122 123 /** 124 * Removes all headers from this message. 125 */ 126 void clearHeaders(); 127 128 /** 129 * @deprecated Use {@link HttpHeaders#getContentLength(HttpMessage)} instead. 130 */ 131 @Deprecated 132 long getContentLength(); 133 134 /** 135 * @deprecated Use {@link HttpHeaders#getContentLength(HttpMessage, long)} instead. 136 */ 137 @Deprecated 138 long getContentLength(long defaultValue); 139 140 /** 141 * Returns {@code true} if and only if this message does not have any 142 * content but the {@link HttpChunk}s, which is generated by 143 * {@link HttpMessageDecoder} consecutively, contain the actual content. 144 * <p> 145 * Please note that this method will keep returning {@code true} if the 146 * {@code "Transfer-Encoding"} of this message is {@code "chunked"}, even if 147 * you attempt to override this property by calling {@link #setChunked(boolean)} 148 * with {@code false}. 149 */ 150 boolean isChunked(); 151 152 /** 153 * Sets if this message does not have any content but the 154 * {@link HttpChunk}s, which is generated by {@link HttpMessageDecoder} 155 * consecutively, contain the actual content. 156 * <p> 157 * If this method is called with {@code true}, the content of this message 158 * becomes {@link ChannelBuffers#EMPTY_BUFFER}. 159 * <p> 160 * Even if this method is called with {@code false}, {@link #isChunked()} 161 * will keep returning {@code true} if the {@code "Transfer-Encoding"} of 162 * this message is {@code "chunked"}. 163 */ 164 void setChunked(boolean chunked); 165 166 /** 167 * @deprecated Use {@link HttpHeaders#isKeepAlive(HttpMessage)} instead. 168 */ 169 @Deprecated 170 boolean isKeepAlive(); 171 }