- All Superinterfaces:
HttpFields
,Iterable<HttpField>
,Supplier<HttpFields>
- All Known Implementing Classes:
HttpFields.Mutable.Wrapper
,HttpFields.MutableHttpFields
,HttpTester.Message
,HttpTester.Request
,HttpTester.Response
- Enclosing interface:
HttpFields
listIterator()
method needs to be implemented, however default implementations
may not be efficient.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.eclipse.jetty.http.HttpFields
HttpFields.ImmutableHttpFields, HttpFields.Mutable, HttpFields.MutableHttpFields
-
Field Summary
Fields inherited from interface org.eclipse.jetty.http.HttpFields
CONNECTION_CLOSE, CONNECTION_KEEPALIVE, CONTENT_LENGTH_0, EMPTY, EXPIRES_01JAN1970
-
Method Summary
Modifier and TypeMethodDescriptiondefault HttpFields.Mutable
Add to or set a field.default HttpFields.Mutable
Add to or set a field.default HttpFields.Mutable
default HttpFields.Mutable
add
(HttpFields fields) default HttpFields.Mutable
add
(HttpHeader header, long value) Add to or set a field.default HttpFields.Mutable
add
(HttpHeader header, String value) Add to or set a field.default HttpFields.Mutable
add
(HttpHeader header, HttpHeaderValue value) default HttpFields.Mutable
Add comma separated values, but only if not already present.default HttpFields.Mutable
addCSV
(HttpHeader header, String... values) Add comma separated values, but only if not already present.default HttpFields.Mutable
addDateField
(String name, long date) Sets the value of a date field.default HttpFields.Mutable
clear()
static HttpField
computeEnsure
(HttpField ensure, String[] values, List<HttpField> fields) Compute ensure field with a multiple valuesstatic HttpField
computeEnsure
(HttpField ensure, List<HttpField> fields) Compute ensure field with a single valuedefault void
computeField
(String name, BiFunction<String, List<HttpField>, HttpField> computeFn) Computes a single field for the given HTTP header name and for existing fields with the same name.default void
computeField
(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) Computes a single field for the given HttpHeader and for existing fields with the same header.default void
ensureField
(HttpField field) Ensure that specific HttpField exists when the field may not exist or may exist and be multi valued.static String
formatCsvExcludingExisting
(QuotedCSV existing, String... values) iterator()
default HttpFields.Mutable
Sets the value of a long field.default HttpFields.Mutable
Set a field.default HttpFields.Mutable
Set a field.default HttpFields.Mutable
default HttpFields.Mutable
put
(HttpHeader header, long value) Sets the value of a long field.default HttpFields.Mutable
put
(HttpHeader header, String value) Set a field.default HttpFields.Mutable
put
(HttpHeader header, HttpHeaderValue value) default HttpFields.Mutable
Sets the value of a date field.default HttpFields.Mutable
putDate
(HttpHeader name, long date) Sets the value of a date field.default HttpFields.Mutable
Remove a field.default HttpFields.Mutable
remove
(EnumSet<HttpHeader> fields) default HttpFields.Mutable
remove
(HttpHeader header) Remove a field.Methods inherited from interface org.eclipse.jetty.http.HttpFields
asImmutable, asString, contains, contains, contains, contains, contains, contains, get, get, get, getCSV, getCSV, getDateField, getDateField, getField, getField, getField, getFieldNames, getFieldNamesCollection, getFields, getFields, getLongField, getLongField, getQualityCSV, getQualityCSV, getQualityCSV, getValues, getValuesList, getValuesList, isEqualTo, size, stream, takeAsImmutable
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
add
Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.- Parameters:
name
- the name of the fieldvalue
- the value of the field.- Returns:
- this builder
-
add
Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.- Parameters:
name
- the name of the fieldvalue
- the value of the field.- Returns:
- this builder
-
add
-
add
Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.- Parameters:
header
- the headervalue
- the value of the field.- Returns:
- this builder
-
add
Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.- Parameters:
header
- the headervalue
- the value of the field.- Returns:
- this builder
-
add
-
add
-
addCSV
Add comma separated values, but only if not already present.- Parameters:
header
- The header to add the value(s) tovalues
- The value(s) to add- Returns:
- this builder
-
addCSV
Add comma separated values, but only if not already present.- Parameters:
name
- The header to add the value(s) tovalues
- The value(s) to add- Returns:
- this builder
-
addDateField
Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value- Returns:
- this builder
-
clear
-
ensureField
Ensure that specific HttpField exists when the field may not exist or may exist and be multi valued. Multiple existing fields are merged into a single field.- Parameters:
field
- The header to ensure is contained. The field is used directly if possible soPreEncodedHttpField
s can be passed. If the value needs to be merged with existing values, then a new field is created.
-
iterator
-
listIterator
ListIterator<HttpField> listIterator() -
put
-
put
Set a field.- Parameters:
name
- the name of the fieldvalue
- the value of the field. If null the field is cleared.- Returns:
- this builder
-
put
-
put
Set a field.- Parameters:
header
- the header name of the fieldvalue
- the value of the field. If null the field is cleared.- Returns:
- this builder
-
put
Set a field.- Parameters:
name
- the name of the fieldlist
- the List value of the field. If null the field is cleared.- Returns:
- this builder
-
putDate
Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value- Returns:
- this builder
-
putDate
Sets the value of a date field.- Parameters:
name
- the field namedate
- the field date value- Returns:
- this builder
-
put
Sets the value of a long field.- Parameters:
header
- the field namevalue
- the field long value- Returns:
- this builder
-
put
Sets the value of a long field.- Parameters:
name
- the field namevalue
- the field long value- Returns:
- this builder
-
computeField
default void computeField(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn) 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. 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);
- Parameters:
header
- the HTTP headercomputeFn
- the compute function
-
computeField
Computes a single field for the given HTTP header name and for existing fields with the same name.
- Parameters:
name
- the HTTP header namecomputeFn
- the compute function- See Also:
-
remove
Remove a field.- Parameters:
header
- the field to remove- Returns:
- this builder
-
remove
-
remove
Remove a field.- Parameters:
name
- the field to remove- Returns:
- this builder
-
formatCsvExcludingExisting
-
computeEnsure
Compute ensure field with a single value- Parameters:
ensure
- The field to ensure existsfields
- The list of existing fields with the same header
-
computeEnsure
Compute ensure field with a multiple values- Parameters:
ensure
- The field to ensure existsvalues
- The QuotedCSV parsed field values.fields
- The list of existing fields with the same header
-