Class HttpTester.Request
- All Implemented Interfaces:
Iterable<HttpField>
,Supplier<HttpFields>
,HttpFields
,HttpFields.Mutable
,HttpParser.HttpHandler
,HttpParser.RequestHandler
- Enclosing class:
- HttpTester
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.http.HttpFields
HttpFields.ImmutableHttpFields, HttpFields.Mutable, HttpFields.MutableHttpFields
Nested classes/interfaces inherited from interface org.eclipse.jetty.http.HttpFields.Mutable
HttpFields.Mutable.Wrapper
-
Field Summary
Fields inherited from interface org.eclipse.jetty.http.HttpFields
CONNECTION_CLOSE, CONNECTION_KEEPALIVE, CONTENT_LENGTH_0, EMPTY, EXPIRES_01JAN1970
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds the givenHttpField
to this instance.add
(HttpFields fields) Adds all theHttpField
s of the givenHttpFields
to this instance.Returns an immutable copy of thisHttpFields
instance.clear()
Removes all the fields from this instance.computeField
(String name, BiFunction<String, List<HttpField>, HttpField> computeFn) Computes a single field for the given HTTP field name and for existing fields with the same name.computeField
(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) Computes a single field for the givenHttpHeader
and for existing fields with the same header.computeField
(T header, BiFunction<T, List<HttpField>, HttpField> computeFn, BiPredicate<HttpField, T> matcher) boolean
getField
(int index) Get a Field by index.Returns the firstHttpField
with the given field name, ornull
if no such field is present.getField
(HttpHeader header) Returns the firstHttpField
with the given field name, ornull
if no such field is present.getURI()
int
hashCode()
iterator()
listIterator
(int index) This method behaves likeHttpFields.Mutable.remove(String)
when the givenvalue
isnull
, otherwise behaves likeHttpFields.Mutable.put(HttpField)
.Puts the givenHttpField
into this instance.put
(HttpHeader header, String value) This method behaves likeHttpFields.Mutable.remove(HttpHeader)
when the givenvalue
isnull
, otherwise behaves likeHttpFields.Mutable.put(HttpField)
.put
(HttpHeader header, HttpHeaderValue value) This method behaves likeHttpFields.Mutable.remove(HttpHeader)
when the givenvalue
isnull
, otherwise behaves likeHttpFields.Mutable.put(HttpField)
.Removes all the fields with the given name.remove
(EnumSet<HttpHeader> headers) Removes all the fields with the given names.remove
(HttpHeader name) Removes all the fields with the given name.void
void
void
int
size()
void
startRequest
(String method, String uri, HttpVersion version) This is the method called by parser when the HTTP request line is parsedstream()
toString()
Methods inherited from class org.eclipse.jetty.http.HttpTester.Message
badMessage, content, contentComplete, earlyEOF, generate, getContent, getContentByteBuffer, getContentBytes, getVersion, headerComplete, isComplete, isEarlyEOF, messageComplete, parsedHeader, setContent, setContent, setContent, setVersion, setVersion
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.http.HttpFields
asString, contains, contains, contains, contains, contains, contains, containsLast, get, get, get, getCSV, getCSV, getDateField, getDateField, getFieldNames, getFieldNamesCollection, getFields, getFields, getLast, getLongField, getLongField, getQualityCSV, getQualityCSV, getQualityCSV, getValues, getValuesList, getValuesList, isEqualTo
Methods inherited from interface org.eclipse.jetty.http.HttpFields.Mutable
add, add, add, add, add, add, addCSV, addCSV, addDateField, ensureField, put, put, put, putDate, putDate
Methods inherited from interface org.eclipse.jetty.http.HttpParser.HttpHandler
badMessage, content, contentComplete, earlyEOF, headerComplete, messageBegin, messageComplete, onViolation, parsedHeader, parsedTrailer
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Request
public Request()
-
-
Method Details
-
startRequest
Description copied from interface:HttpParser.RequestHandler
This is the method called by parser when the HTTP request line is parsed- Specified by:
startRequest
in interfaceHttpParser.RequestHandler
- Parameters:
method
- The methoduri
- The raw bytes of the URI. These are copied into a ByteBuffer that will not be changed until this parser is reset and reused.version
- the http version in use
-
getMethod
-
getURI
-
setMethod
-
setURI
-
getMetaData
- Specified by:
getMetaData
in classHttpTester.Message
-
toString
-
setHeader
-
add
Description copied from interface:HttpFields.Mutable
Adds the given
HttpField
to this instance.- Specified by:
add
in interfaceHttpFields.Mutable
- Parameters:
field
- theHttpField
to add- Returns:
- this instance
-
add
Description copied from interface:HttpFields.Mutable
Adds all the
HttpField
s of the givenHttpFields
to this instance.- Specified by:
add
in interfaceHttpFields.Mutable
- Parameters:
fields
- the fields to add- Returns:
- this instance
-
asImmutable
Description copied from interface:HttpFields
Returns an immutable copy of this
HttpFields
instance.- Specified by:
asImmutable
in interfaceHttpFields
- Returns:
- a new immutable copy of this
HttpFields
instance
-
clear
Description copied from interface:HttpFields.Mutable
Removes all the fields from this instance.
- Specified by:
clear
in interfaceHttpFields.Mutable
- Returns:
- this instance
-
hashCode
public int hashCode() -
equals
-
getField
Get a Field by index.- Specified by:
getField
in interfaceHttpFields
- Parameters:
index
- the field index- Returns:
- A Field value or null if the Field value has not been set
-
getField
Description copied from interface:HttpFields
Returns the first
HttpField
with the given field name, ornull
if no such field is present.- Specified by:
getField
in interfaceHttpFields
- Parameters:
header
- the field name to search for- Returns:
- the first
HttpField
with the given field name, ornull
if no such field is present
-
getField
Description copied from interface:HttpFields
Returns the first
HttpField
with the given field name, ornull
if no such field is present.The comparison of field name is case-insensitive via
HttpField.is(String)
.- Specified by:
getField
in interfaceHttpFields
- Parameters:
name
- the case-insensitive field name to search for- Returns:
- the first
HttpField
with the given field name, ornull
if no such field is present
-
iterator
- Specified by:
iterator
in interfaceHttpFields
- Specified by:
iterator
in interfaceIterable<HttpField>
-
listIterator
- Specified by:
listIterator
in interfaceHttpFields
- Returns:
- an iterator over the
HttpField
s in thisHttpFields
. - See Also:
-
listIterator
- Specified by:
listIterator
in interfaceHttpFields
- Returns:
- an iterator over the
HttpField
s in thisHttpFields
starting at the given index. - See Also:
-
put
Description copied from interface:HttpFields.Mutable
Puts the given
HttpField
into this instance.If a fields with the same name is present, the given field replaces it, and other existing fields with the same name are removed, so that only the given field will be present.
If a field with the same name is not present, the given field will be added.
- Specified by:
put
in interfaceHttpFields.Mutable
- Parameters:
field
- the field to put- Returns:
- this instance
-
put
Description copied from interface:HttpFields.Mutable
This method behaves like
HttpFields.Mutable.remove(String)
when the givenvalue
isnull
, otherwise behaves likeHttpFields.Mutable.put(HttpField)
.- Specified by:
put
in interfaceHttpFields.Mutable
- Parameters:
name
- the name of the fieldvalue
- the value of the field; ifnull
the field is removed- Returns:
- this instance
-
put
Description copied from interface:HttpFields.Mutable
This method behaves like
HttpFields.Mutable.remove(HttpHeader)
when the givenvalue
isnull
, otherwise behaves likeHttpFields.Mutable.put(HttpField)
.- Specified by:
put
in interfaceHttpFields.Mutable
- Parameters:
header
- the name of the fieldvalue
- the value of the field; ifnull
the field is removed- Returns:
- this instance
-
put
Description copied from interface:HttpFields.Mutable
This method behaves like
HttpFields.Mutable.remove(HttpHeader)
when the givenvalue
isnull
, otherwise behaves likeHttpFields.Mutable.put(HttpField)
.- Specified by:
put
in interfaceHttpFields.Mutable
- Parameters:
header
- the name of the fieldvalue
- the value of the field; ifnull
the field is removed- Returns:
- this instance
-
computeField
public HttpFields.Mutable computeField(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) Description copied from interface:HttpFields.Mutable
Computes a single field for the given
HttpHeader
and for existing fields with the same header.The compute function receives the field name and a list of fields with the same name so that their values can be used to compute the value of the field that is returned by the compute function parameter. If the compute function returns
null
, the fields with the given name are removed.This method comes handy when you want to add an HTTP header if it does not exist, or add a value if the HTTP header already exists, similarly to
Map.compute(Object, BiFunction)
.This method can be used to
put
a new field (or blindly replace its value):httpFields.computeField("X-New-Header", (name, fields) -> new HttpField(name, "NewValue"));
This method can be used to coalesce many fields into one:
// Input: GET / HTTP/1.1 Host: localhost Cookie: foo=1 Cookie: bar=2,baz=3 User-Agent: Jetty // Computation: httpFields.computeField("Cookie", (name, fields) -> { // No cookies, nothing to do. if (fields == null) return null; // Coalesces all cookies. String coalesced = fields.stream() .flatMap(field -> Stream.of(field.getValues())) .collect(Collectors.joining(", ")); // Returns a single Cookie header with all cookies. return new HttpField(name, coalesced); } // Output: GET / HTTP/1.1 Host: localhost Cookie: foo=1, bar=2, baz=3 User-Agent: Jetty
This method can be used to replace a field:
httpFields.computeField("X-Length", (name, fields) -> { if (fields == null) return null; // Get any value among the X-Length headers. String length = fields.stream() .map(HttpField::getValue) .findAny() .orElse("0"); // Replace X-Length headers with X-Capacity header. return new HttpField("X-Capacity", length); });
This method can be used to remove a field:
httpFields.computeField("Connection", (name, fields) -> null);
- Specified by:
computeField
in interfaceHttpFields.Mutable
- Parameters:
header
- the field namecomputeFn
- the compute function- Returns:
- this instance
-
computeField
public HttpFields.Mutable computeField(String name, BiFunction<String, List<HttpField>, HttpField> computeFn) Description copied from interface:HttpFields.Mutable
Computes a single field for the given HTTP field name and for existing fields with the same name.
- Specified by:
computeField
in interfaceHttpFields.Mutable
- Parameters:
name
- the field namecomputeFn
- the compute function- Returns:
- this instance
- See Also:
-
computeField
public <T> HttpFields.Mutable computeField(T header, BiFunction<T, List<HttpField>, HttpField> computeFn, BiPredicate<HttpField, T> matcher) -
remove
Description copied from interface:HttpFields.Mutable
Removes all the fields with the given name.
- Specified by:
remove
in interfaceHttpFields.Mutable
- Parameters:
name
- the name of the fields to remove- Returns:
- this instance
-
remove
Description copied from interface:HttpFields.Mutable
Removes all the fields with the given names.
- Specified by:
remove
in interfaceHttpFields.Mutable
- Parameters:
headers
- the names of the fields to remove- Returns:
- this instance
-
remove
Description copied from interface:HttpFields.Mutable
Removes all the fields with the given name.
- Specified by:
remove
in interfaceHttpFields.Mutable
- Parameters:
name
- the name of the fields to remove- Returns:
- this instance
-
size
public int size()- Specified by:
size
in interfaceHttpFields
- Returns:
- the number of
HttpField
s in this instance
-
stream
- Specified by:
stream
in interfaceHttpFields
- Returns:
- a sequential stream of the
HttpField
s in this instance
-