Class HttpTester.Response
- All Implemented Interfaces:
Iterable<HttpField>, Supplier<HttpFields>, HttpFields, HttpFields.Mutable, HttpParser.HttpHandler, HttpParser.ResponseHandler
- Enclosing class:
HttpTester
-
Nested Class Summary
Nested classes/interfaces inherited from interface HttpFields
HttpFields.ImmutableHttpFields, HttpFields.Mutable, HttpFields.MutableHttpFieldsNested classes/interfaces inherited from interface HttpFields.Mutable
HttpFields.Mutable.Wrapper -
Field Summary
Fields inherited from interface HttpFields
CONNECTION_CLOSE, CONNECTION_KEEPALIVE, CONTENT_LENGTH_0, EMPTY, EXPIRES_01JAN1970 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the givenHttpFieldto this instance.add(HttpFields fields) Adds all theHttpFields of the givenHttpFieldsto this instance.Returns an immutable copy of thisHttpFieldsinstance.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 givenHttpHeaderand for existing fields with the same header.computeField(T header, BiFunction<T, List<HttpField>, HttpField> computeFn, BiPredicate<HttpField, T> matcher) booleangetField(int index) Get a Field by index.Returns the firstHttpFieldwith the given field name, ornullif no such field is present.getField(HttpHeader header) Returns the firstHttpFieldwith the given field name, ornullif no such field is present.intinthashCode()iterator()listIterator(int index) This method behaves likeHttpFields.Mutable.remove(String)when the givenvalueisnull, otherwise behaves likeHttpFields.Mutable.put(HttpField).Puts the givenHttpFieldinto this instance.put(HttpHeader header, String value) This method behaves likeHttpFields.Mutable.remove(HttpHeader)when the givenvalueisnull, otherwise behaves likeHttpFields.Mutable.put(HttpField).put(HttpHeader header, HttpHeaderValue value) This method behaves likeHttpFields.Mutable.remove(HttpHeader)when the givenvalueisnull, 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.intsize()voidstartResponse(HttpVersion version, int status, String reason) This is the method called by parser when the HTTP request line is parsedstream()toString()Methods inherited from class HttpTester.Message
badMessage, content, contentComplete, earlyEOF, generate, getContent, getContentByteBuffer, getContentBytes, getVersion, headerComplete, isComplete, isEarlyEOF, messageComplete, parsedHeader, setContent, setContent, setContent, setVersion, setVersionMethods inherited from interface 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, isEqualToMethods inherited from interface HttpFields.Mutable
add, add, add, add, add, add, addCSV, addCSV, addDateField, ensureField, put, put, put, putDate, putDateMethods inherited from interface HttpParser.HttpHandler
badMessage, content, contentComplete, earlyEOF, headerComplete, messageBegin, messageComplete, onViolation, parsedHeader, parsedTrailerMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
Response
public Response()
-
-
Method Details
-
startResponse
Description copied from interface:HttpParser.ResponseHandlerThis is the method called by parser when the HTTP request line is parsed- Specified by:
startResponsein interfaceHttpParser.ResponseHandler- Parameters:
version- the http version in usestatus- the response statusreason- the response reason phrase
-
getStatus
public int getStatus() -
getReason
-
getMetaData
- Specified by:
getMetaDatain classHttpTester.Message
-
toString
-
add
Description copied from interface:HttpFields.MutableAdds the given
HttpFieldto this instance.- Specified by:
addin interfaceHttpFields.Mutable- Parameters:
field- theHttpFieldto add- Returns:
- this instance
-
add
Description copied from interface:HttpFields.MutableAdds all the
HttpFields of the givenHttpFieldsto this instance.- Specified by:
addin interfaceHttpFields.Mutable- Parameters:
fields- the fields to add- Returns:
- this instance
-
asImmutable
Description copied from interface:HttpFieldsReturns an immutable copy of this
HttpFieldsinstance.- Specified by:
asImmutablein interfaceHttpFields- Returns:
- a new immutable copy of this
HttpFieldsinstance
-
clear
Description copied from interface:HttpFields.MutableRemoves all the fields from this instance.
- Specified by:
clearin interfaceHttpFields.Mutable- Returns:
- this instance
-
hashCode
-
equals
-
getField
Get a Field by index.- Specified by:
getFieldin 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:HttpFieldsReturns the first
HttpFieldwith the given field name, ornullif no such field is present.- Specified by:
getFieldin interfaceHttpFields- Parameters:
header- the field name to search for- Returns:
- the first
HttpFieldwith the given field name, ornullif no such field is present
-
getField
Description copied from interface:HttpFieldsReturns the first
HttpFieldwith the given field name, ornullif no such field is present.The comparison of field name is case-insensitive via
HttpField.is(String).- Specified by:
getFieldin interfaceHttpFields- Parameters:
name- the case-insensitive field name to search for- Returns:
- the first
HttpFieldwith the given field name, ornullif no such field is present
-
iterator
-
listIterator
- Specified by:
listIteratorin interfaceHttpFields- Returns:
- an iterator over the
HttpFields in thisHttpFields. - See Also:
-
listIterator
- Specified by:
listIteratorin interfaceHttpFields- Returns:
- an iterator over the
HttpFields in thisHttpFieldsstarting at the given index. - See Also:
-
put
Description copied from interface:HttpFields.MutablePuts the given
HttpFieldinto 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:
putin interfaceHttpFields.Mutable- Parameters:
field- the field to put- Returns:
- this instance
-
put
Description copied from interface:HttpFields.MutableThis method behaves like
HttpFields.Mutable.remove(String)when the givenvalueisnull, otherwise behaves likeHttpFields.Mutable.put(HttpField).- Specified by:
putin interfaceHttpFields.Mutable- Parameters:
name- the name of the fieldvalue- the value of the field; ifnullthe field is removed- Returns:
- this instance
-
put
Description copied from interface:HttpFields.MutableThis method behaves like
HttpFields.Mutable.remove(HttpHeader)when the givenvalueisnull, otherwise behaves likeHttpFields.Mutable.put(HttpField).- Specified by:
putin interfaceHttpFields.Mutable- Parameters:
header- the name of the fieldvalue- the value of the field; ifnullthe field is removed- Returns:
- this instance
-
put
Description copied from interface:HttpFields.MutableThis method behaves like
HttpFields.Mutable.remove(HttpHeader)when the givenvalueisnull, otherwise behaves likeHttpFields.Mutable.put(HttpField).- Specified by:
putin interfaceHttpFields.Mutable- Parameters:
header- the name of the fieldvalue- the value of the field; ifnullthe field is removed- Returns:
- this instance
-
computeField
public HttpFields.Mutable computeField(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) Description copied from interface:HttpFields.MutableComputes a single field for the given
HttpHeaderand 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
puta 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: JettyThis 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:
computeFieldin 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.MutableComputes a single field for the given HTTP field name and for existing fields with the same name.
- Specified by:
computeFieldin 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.MutableRemoves all the fields with the given name.
- Specified by:
removein interfaceHttpFields.Mutable- Parameters:
name- the name of the fields to remove- Returns:
- this instance
-
remove
Description copied from interface:HttpFields.MutableRemoves all the fields with the given names.
- Specified by:
removein interfaceHttpFields.Mutable- Parameters:
headers- the names of the fields to remove- Returns:
- this instance
-
remove
Description copied from interface:HttpFields.MutableRemoves all the fields with the given name.
- Specified by:
removein interfaceHttpFields.Mutable- Parameters:
name- the name of the fields to remove- Returns:
- this instance
-
size
public int size()- Specified by:
sizein interfaceHttpFields- Returns:
- the number of
HttpFields in this instance
-
stream
- Specified by:
streamin interfaceHttpFields- Returns:
- a sequential stream of the
HttpFields in this instance
-