The Header class encapsulates a single HTTP header.
| 1103 | * The {@code Header} class encapsulates a single HTTP header. |
| 1104 | */ |
| 1105 | public static class Header { |
| 1106 | |
| 1107 | protected final String name; |
| 1108 | protected final String value; |
| 1109 | |
| 1110 | /** |
| 1111 | * Constructs a header with the given name and value. |
| 1112 | * Leading and trailing whitespace are trimmed. |
| 1113 | * |
| 1114 | * @param name the header name |
| 1115 | * @param value the header value |
| 1116 | * @throws NullPointerException if name or value is null |
| 1117 | * @throws IllegalArgumentException if name is empty |
| 1118 | */ |
| 1119 | public Header(String name, String value) { |
| 1120 | this.name = name.trim(); |
| 1121 | this.value = value.trim(); |
| 1122 | // RFC2616#14.23 - header can have an empty value (e.g. Host) |
| 1123 | if (this.name.length() == 0) // but name cannot be empty |
| 1124 | throw new IllegalArgumentException("name cannot be empty"); |
| 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * Returns this header's name. |
| 1129 | * |
| 1130 | * @return this header's name |
| 1131 | */ |
| 1132 | public String getName() { return name; } |
| 1133 | |
| 1134 | /** |
| 1135 | * Returns this header's value. |
| 1136 | * |
| 1137 | * @return this header's value |
| 1138 | */ |
| 1139 | public String getValue() { return value; } |
| 1140 | } |
| 1141 | |
| 1142 | /** |
| 1143 | * The {@code Headers} class encapsulates a collection of HTTP headers. |
nothing calls this directly
no outgoing calls
no test coverage detected