Package com.authlete.http
Class ForwardedElement
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<ForwardedPair>,Collection<ForwardedPair>,List<ForwardedPair>,RandomAccess,SequencedCollection<ForwardedPair>
This class represents the forwarded element as defined in RFC 7239:
Forwarded HTTP Extension, Section 4. Forwarded HTTP Header Field.
Definition
Forwarded = 1#forwarded-element
forwarded-element =
[ forwarded-pair ] *( ";" [ forwarded-pair ] )
forwarded-pair = token "=" value
value = token / quoted-string
token = <Defined in [RFC7230], Section 3.2.6>
quoted-string = <Defined in [RFC7230], Section 3.2.6>
Sample Code
ForwardedElement element = ForwardedElement.parse(
"for=192.0.2.60;proto=http;by=203.0.113.43;host=example.com");
assertNotNull(element);
assertEquals(4, element.size());
// for
ForwardedPair forPair = element.get(0);
assertNotNull(forPair);
Token forName = forPair.getName();
assertNotNull(forName);
assertEquals("for", forName.getValue());
Object forValue = forPair.getValue();
assertNotNull(forValue);
assertEquals(Token.class, forValue.getClass());
assertEquals("192.0.2.60", ((Token)forValue).getValue());
// proto
ForwardedPair protoPair = element.get(1);
assertNotNull(protoPair);
Token protoName = protoPair.getName();
assertNotNull(protoName);
assertEquals("proto", protoName.getValue());
Object protoValue = protoPair.getValue();
assertNotNull(protoValue);
assertEquals(Token.class, protoValue.getClass());
assertEquals("http", ((Token)protoValue).getValue());
// by
ForwardedPair byPair = element.get(2);
assertNotNull(byPair);
Token byName = byPair.getName();
assertNotNull(byName);
assertEquals("by", byName.getValue());
Object byValue = byPair.getValue();
assertNotNull(byValue);
assertEquals(Token.class, byValue.getClass());
assertEquals("203.0.113.43", ((Token)byValue).getValue());
// host
ForwardedPair hostPair = element.get(3);
assertNotNull(hostPair);
Token hostName = hostPair.getName();
assertNotNull(hostName);
assertEquals("host", hostName.getValue());
Object hostValue = hostPair.getValue();
assertNotNull(hostValue);
assertEquals(Token.class, hostValue.getClass());
assertEquals("example.com", ((Token)hostValue).getValue());
// Search
assertEquals("192.0.2.60", element.getFor());
assertEquals("http", element.getProto());
assertEquals("203.0.113.43", element.getBy());
assertEquals("example.com", element.getHost());
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor.ForwardedElement(int capacity) A constructor with the initial capacity.ForwardedElement(Collection<? extends ForwardedPair> elements) A constructor with the initial elements. -
Method Summary
Modifier and TypeMethodDescriptiongetBy()Get the value of the forwarded pair whose parameter name is "by" (case-insensitive).Get the forwarded pair whose parameter name is "by" (case-insensitive).getFor()Get the value of the forwarded pair whose parameter name is "for" (case-insensitive).Get the forwarded pair whose parameter name is "for" (case-insensitive).getHost()Get the value of the forwarded pair whose parameter name is "host" (case-insensitive).Get the forwarded pair whose parameter name is "host" (case-insensitive).Get the forwarded pair that has the specified parameter name.getProto()Get the value of the forwarded pair whose parameter name is "proto" (case-insensitive).Get the forwarded pair whose parameter name is "proto" (case-insensitive).Get the value of the forwarded pair that has the specified parameter name.static ForwardedElementParse the input string as a forwarded element.toString()Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
ForwardedElement
public ForwardedElement()The default constructor. -
ForwardedElement
A constructor with the initial elements.- Parameters:
elements- The initial elements.
-
ForwardedElement
public ForwardedElement(int capacity) A constructor with the initial capacity.- Parameters:
capacity- The initial capacity.
-
-
Method Details
-
getBy
Get the value of the forwarded pair whose parameter name is "by" (case-insensitive).- Returns:
- The value of the forwarded pair whose parameter name is "by"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getByPair
Get the forwarded pair whose parameter name is "by" (case-insensitive).- Returns:
- The forwarded pair whose parameter name is "by"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getFor
Get the value of the forwarded pair whose parameter name is "for" (case-insensitive).- Returns:
- The value of the forwarded pair whose parameter name is "for"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getForPair
Get the forwarded pair whose parameter name is "for" (case-insensitive).- Returns:
- The forwarded pair whose parameter name is "for"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getHost
Get the value of the forwarded pair whose parameter name is "host" (case-insensitive).- Returns:
- The value of the forwarded pair whose parameter name is "host"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getHostPair
Get the forwarded pair whose parameter name is "host" (case-insensitive).- Returns:
- The forwarded pair whose parameter name is "host"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getProto
Get the value of the forwarded pair whose parameter name is "proto" (case-insensitive).- Returns:
- The value of the forwarded pair whose parameter name is "proto"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getProtoPair
Get the forwarded pair whose parameter name is "proto" (case-insensitive).- Returns:
- The forwarded pair whose parameter name is "proto"
(case-insensitive).
nullis returned if this forwarded element does not include such a forwarded pair.
-
getPair
Get the forwarded pair that has the specified parameter name.- Parameters:
parameterName- A parameter name such as "for" (case-insensitive).- Returns:
- The forwarded pair that has the specified parameter name.
nullis returned if this forwarded element does not include such a forwarded pair.
-
getValue
Get the value of the forwarded pair that has the specified parameter name.- Parameters:
parameterName- A parameter name such as "for" (case-insensitive).- Returns:
- The value of the forwarded pair that has the specified parameter name.
nullis returned if this forwarded element does not include such a forwarded pair.
-
toString
- Overrides:
toStringin classAbstractCollection<ForwardedPair>
-
parse
Parse the input string as a forwarded element.- Parameters:
input- A string to be parsed as a forwarded element.- Returns:
- The parsed forwarded element.
- Throws:
ParseCancellationException- The input string could not be parsed successfully.
-