2008-11-19 08:22:15 +01:00
|
|
|
/*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Copyright 2009 Red Hat, Inc.
|
2009-06-19 19:48:17 +02:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Red Hat 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:
|
2008-11-19 08:22:15 +01:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-19 08:22:15 +01:00
|
|
|
*
|
2009-08-28 09:15:49 +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.
|
2008-11-19 08:22:15 +01:00
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.handler.codec.http;
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
2008-11-19 08:22:15 +01:00
|
|
|
import java.util.List;
|
2010-01-08 09:29:37 +01:00
|
|
|
import java.util.Map;
|
2008-11-19 08:22:15 +01:00
|
|
|
import java.util.Set;
|
|
|
|
|
2011-12-09 04:38:59 +01:00
|
|
|
import io.netty.buffer.ChannelBuffer;
|
|
|
|
import io.netty.buffer.ChannelBuffers;
|
2008-11-19 08:22:15 +01:00
|
|
|
|
|
|
|
/**
|
2009-06-19 17:01:47 +02:00
|
|
|
* An HTTP message which provides common properties for {@link HttpRequest} and
|
2009-06-19 16:15:20 +02:00
|
|
|
* {@link HttpResponse}.
|
2009-07-20 05:37:35 +02:00
|
|
|
* @see HttpHeaders
|
|
|
|
*
|
|
|
|
* @apiviz.landmark
|
2011-12-09 04:38:59 +01:00
|
|
|
* @apiviz.has io.netty.handler.codec.http.HttpChunk oneway - - is followed by
|
2008-11-19 08:22:15 +01:00
|
|
|
*/
|
|
|
|
public interface HttpMessage {
|
2009-06-19 16:15:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the header value with the specified header name. If there are
|
|
|
|
* more than one header value for the specified header name, the first
|
|
|
|
* value is returned.
|
|
|
|
*
|
|
|
|
* @return the header value or {@code null} if there is no such header
|
2011-12-09 05:43:34 +01:00
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
String getHeader(String name);
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Returns the header values with the specified header name.
|
|
|
|
*
|
2009-06-30 11:39:07 +02:00
|
|
|
* @return the {@link List} of header values. An empty list if there is no
|
|
|
|
* such header.
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
List<String> getHeaders(String name);
|
|
|
|
|
2010-01-08 09:29:37 +01:00
|
|
|
/**
|
|
|
|
* Returns the all header names and values that this message contains.
|
|
|
|
*
|
|
|
|
* @return the {@link List} of the header name-value pairs. An empty list
|
|
|
|
* if there is no header in this message.
|
|
|
|
*/
|
|
|
|
List<Map.Entry<String, String>> getHeaders();
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Returns {@code true} if and only if there is a header with the specified
|
|
|
|
* header name.
|
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
boolean containsHeader(String name);
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Returns the {@link Set} of all header names that this message contains.
|
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
Set<String> getHeaderNames();
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Returns the protocol version of this message.
|
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
HttpVersion getProtocolVersion();
|
|
|
|
|
2009-11-20 05:12:16 +01:00
|
|
|
/**
|
|
|
|
* Sets the protocol version of this message.
|
|
|
|
*/
|
|
|
|
void setProtocolVersion(HttpVersion version);
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
2009-11-17 08:19:28 +01:00
|
|
|
* Returns the content of this message. If there is no content or
|
|
|
|
* {@link #isChunked()} returns {@code true}, an
|
2009-06-19 16:15:20 +02:00
|
|
|
* {@link ChannelBuffers#EMPTY_BUFFER} is returned.
|
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
ChannelBuffer getContent();
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Sets the content of this message. If {@code null} is specified,
|
|
|
|
* the content of this message will be set to {@link ChannelBuffers#EMPTY_BUFFER}.
|
|
|
|
*/
|
|
|
|
void setContent(ChannelBuffer content);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new header with the specified name and value.
|
2011-05-11 11:09:49 +02:00
|
|
|
* If the specified value is not a {@link String}, it is converted into a
|
|
|
|
* {@link String} by {@link Object#toString()}, except for {@link Date}
|
|
|
|
* and {@link Calendar} which are formatted to the date format defined in
|
|
|
|
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2010-01-26 05:31:54 +01:00
|
|
|
void addHeader(String name, Object value);
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Sets a new header with the specified name and value. If there is an
|
|
|
|
* existing header with the same name, the existing header is removed.
|
2011-05-11 11:09:49 +02:00
|
|
|
* If the specified value is not a {@link String}, it is converted into a
|
|
|
|
* {@link String} by {@link Object#toString()}, except for {@link Date}
|
|
|
|
* and {@link Calendar} which are formatted to the date format defined in
|
|
|
|
* <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC2616</a>.
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2010-01-26 05:31:54 +01:00
|
|
|
void setHeader(String name, Object value);
|
2008-12-04 03:17:22 +01:00
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Sets a new header with the specified name and values. If there is an
|
|
|
|
* existing header with the same name, the existing header is removed.
|
2011-05-11 11:09:49 +02:00
|
|
|
* This method can be represented approximately as the following code:
|
|
|
|
* <pre>
|
|
|
|
* m.removeHeader(name);
|
|
|
|
* for (Object v: values) {
|
|
|
|
* if (v == null) {
|
|
|
|
* break;
|
|
|
|
* }
|
|
|
|
* m.addHeader(name, v);
|
|
|
|
* }
|
|
|
|
* </pre>
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2010-01-26 05:31:54 +01:00
|
|
|
void setHeader(String name, Iterable<?> values);
|
2008-11-19 08:22:15 +01:00
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Removes the header with the specified name.
|
|
|
|
*/
|
2008-12-01 10:34:45 +01:00
|
|
|
void removeHeader(String name);
|
|
|
|
|
2009-06-19 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Removes all headers from this message.
|
|
|
|
*/
|
|
|
|
void clearHeaders();
|
|
|
|
|
|
|
|
/**
|
2009-11-17 07:02:42 +01:00
|
|
|
* Returns {@code true} if and only if this message does not have any
|
|
|
|
* content but the {@link HttpChunk}s, which is generated by
|
|
|
|
* {@link HttpMessageDecoder} consecutively, contain the actual content.
|
2009-11-17 08:43:43 +01:00
|
|
|
* <p>
|
|
|
|
* Please note that this method will keep returning {@code true} if the
|
|
|
|
* {@code "Transfer-Encoding"} of this message is {@code "chunked"}, even if
|
|
|
|
* you attempt to override this property by calling {@link #setChunked(boolean)}
|
|
|
|
* with {@code false}.
|
2009-06-19 16:15:20 +02:00
|
|
|
*/
|
2008-11-19 08:22:15 +01:00
|
|
|
boolean isChunked();
|
|
|
|
|
2009-11-17 08:19:28 +01:00
|
|
|
/**
|
|
|
|
* Sets if this message does not have any content but the
|
|
|
|
* {@link HttpChunk}s, which is generated by {@link HttpMessageDecoder}
|
|
|
|
* consecutively, contain the actual content.
|
|
|
|
* <p>
|
|
|
|
* If this method is called with {@code true}, the content of this message
|
|
|
|
* becomes {@link ChannelBuffers#EMPTY_BUFFER}.
|
2009-11-17 08:43:43 +01:00
|
|
|
* <p>
|
|
|
|
* Even if this method is called with {@code false}, {@link #isChunked()}
|
|
|
|
* will keep returning {@code true} if the {@code "Transfer-Encoding"} of
|
|
|
|
* this message is {@code "chunked"}.
|
2009-11-17 08:19:28 +01:00
|
|
|
*/
|
|
|
|
void setChunked(boolean chunked);
|
2008-11-19 08:22:15 +01:00
|
|
|
}
|