Reapply changes to HttpHeaders without indenting problems so that we can

make sure of additions.
This commit is contained in:
vibul 2012-04-27 09:48:15 +10:00
parent 66b4735acd
commit e8b016461c

View File

@ -21,10 +21,10 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/**
* Provides the constants for the standard HTTP header names and values and
* commonly used utility methods that accesses an {@link HttpMessage}.
*
* @apiviz.landmark
* @apiviz.stereotype static
*/
@ -32,7 +32,6 @@ public class HttpHeaders {
/**
* Standard HTTP header names.
*
* @apiviz.stereotype static
*/
public static final class Names {
@ -304,7 +303,6 @@ public class HttpHeaders {
/**
* Standard HTTP header values.
*
* @apiviz.stereotype static
*/
public static final class Values {
@ -442,6 +440,7 @@ public class HttpHeaders {
}
}
/**
* Returns {@code true} if and only if the connection can remain open and
* thus 'kept alive'. This methods respects the value of the
@ -472,14 +471,12 @@ public class HttpHeaders {
* <ul>
* <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
* <li>remove otherwise.</li>
* </ul>
* </li>
* </ul></li>
* <li>If the connection is closed by default:
* <ul>
* <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
* <li>remove otherwise.</li>
* </ul>
* </li>
* </ul></li>
* </ul>
*/
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
@ -500,8 +497,8 @@ public class HttpHeaders {
/**
* 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.
* 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
*/
@ -511,14 +508,13 @@ public class HttpHeaders {
/**
* 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.
* more than one header value for the specified header name, the first
* value is returned.
*
* @return the header value or the {@code defaultValue} if there is no such
* header
*/
public static String getHeader(HttpMessage message, String name,
String defaultValue) {
public static String getHeader(HttpMessage message, String name, String defaultValue) {
String value = message.getHeader(name);
if (value == null) {
return defaultValue;
@ -538,8 +534,7 @@ public class HttpHeaders {
* 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.
*/
public static void setHeader(HttpMessage message, String name,
Iterable<?> values) {
public static void setHeader(HttpMessage message, String name, Iterable<?> values) {
message.setHeader(name, values);
}
@ -551,14 +546,13 @@ public class HttpHeaders {
}
/**
* Returns the integer 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.
* Returns the integer 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
* @throws NumberFormatException
* if there is no such header or the header value is not a
* number
* if there is no such header or the header value is not a number
*/
public static int getIntHeader(HttpMessage message, String name) {
String value = getHeader(message, name);
@ -569,15 +563,14 @@ public class HttpHeaders {
}
/**
* Returns the integer 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.
* Returns the integer 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 the {@code defaultValue} if there is no such
* header or the header value is not a number
*/
public static int getIntHeader(HttpMessage message, String name,
int defaultValue) {
public static int getIntHeader(HttpMessage message, String name, int defaultValue) {
String value = getHeader(message, name);
if (value == null) {
return defaultValue;
@ -591,19 +584,18 @@ public class HttpHeaders {
}
/**
* Sets a new integer header with the specified name and value. If there is
* an existing header with the same name, the existing header is removed.
* Sets a new integer header with the specified name and value. If there
* is an existing header with the same name, the existing header is removed.
*/
public static void setIntHeader(HttpMessage message, String name, int value) {
message.setHeader(name, value);
}
/**
* Sets a new integer header with the specified name and values. If there is
* an existing header with the same name, the existing header is removed.
* Sets a new integer header with the specified name and values. If there
* is an existing header with the same name, the existing header is removed.
*/
public static void setIntHeader(HttpMessage message, String name,
Iterable<Integer> values) {
public static void setIntHeader(HttpMessage message, String name, Iterable<Integer> values) {
message.setHeader(name, values);
}
@ -615,21 +607,21 @@ public class HttpHeaders {
}
/**
* Returns the length of the content. Please note that this value is not
* retrieved from {@link HttpMessage#getContent()} but from the
* Returns the length of the content. Please note that this value is
* not retrieved from {@link HttpMessage#getContent()} but from the
* {@code "Content-Length"} header, and thus they are independent from each
* other.
*
* @return the content length or {@code 0} if this message does not have the
* {@code "Content-Length"} header
* @return the content length or {@code 0} if this message does not have
* the {@code "Content-Length"} header
*/
public static long getContentLength(HttpMessage message) {
return getContentLength(message, 0L);
}
/**
* Returns the length of the content. Please note that this value is not
* retrieved from {@link HttpMessage#getContent()} but from the
* Returns the length of the content. Please note that this value is
* not retrieved from {@link HttpMessage#getContent()} but from the
* {@code "Content-Length"} header, and thus they are independent from each
* other.
*
@ -645,16 +637,16 @@ public class HttpHeaders {
// WebSockset messages have constant content-lengths.
if (message instanceof HttpRequest) {
HttpRequest req = (HttpRequest) message;
if (HttpMethod.GET.equals(req.getMethod())
&& req.containsHeader(Names.SEC_WEBSOCKET_KEY1)
&& req.containsHeader(Names.SEC_WEBSOCKET_KEY2)) {
if (HttpMethod.GET.equals(req.getMethod()) &&
req.containsHeader(Names.SEC_WEBSOCKET_KEY1) &&
req.containsHeader(Names.SEC_WEBSOCKET_KEY2)) {
return 8;
}
} else if (message instanceof HttpResponse) {
HttpResponse res = (HttpResponse) message;
if (res.getStatus().getCode() == 101
&& res.containsHeader(Names.SEC_WEBSOCKET_ORIGIN)
&& res.containsHeader(Names.SEC_WEBSOCKET_LOCATION)) {
if (res.getStatus().getCode() == 101 &&
res.containsHeader(Names.SEC_WEBSOCKET_ORIGIN) &&
res.containsHeader(Names.SEC_WEBSOCKET_LOCATION)) {
return 16;
}
}
@ -735,8 +727,8 @@ public class HttpHeaders {
/**
* Sets or removes the {@code "Expect: 100-continue"} header to / from the
* specified message. If the specified {@code value} is {@code true}, the
* {@code "Expect: 100-continue"} header is set and all other previous
* specified message. If the specified {@code value} is {@code true},
* the {@code "Expect: 100-continue"} header is set and all other previous
* {@code "Expect"} headers are removed. Otherwise, all {@code "Expect"}
* headers are removed completely.
*/
@ -949,7 +941,8 @@ public class HttpHeaders {
}
List<Map.Entry<String, String>> getHeaders() {
List<Map.Entry<String, String>> all = new LinkedList<Map.Entry<String, String>>();
List<Map.Entry<String, String>> all =
new LinkedList<Map.Entry<String, String>>();
Entry e = head.after;
while (e != head) {
@ -964,7 +957,8 @@ public class HttpHeaders {
}
Set<String> getHeaderNames() {
Set<String> names = new TreeSet<String>(CaseIgnoringComparator.INSTANCE);
Set<String> names =
new TreeSet<String>(CaseIgnoringComparator.INSTANCE);
Entry e = head.after;
while (e != head) {