- All Superinterfaces:
HttpFields,Iterable<HttpField>
- All Known Implementing Classes:
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 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, EMPTY, EXPIRES_01JAN1970 -
Method Summary
Modifier and TypeMethodDescriptiondefault HttpFields.MutableAdd to or set a field.default HttpFields.Mutabledefault HttpFields.Mutableadd(HttpFields fields) default HttpFields.Mutableadd(HttpHeader header, String value) Add to or set a field.default HttpFields.Mutableadd(HttpHeader header, HttpHeaderValue value) default HttpFields.MutableAdd comma separated values, but only if not already present.default HttpFields.MutableaddCSV(HttpHeader header, String... values) Add comma separated values, but only if not already present.default HttpFields.MutableaddDateField(String name, long date) Sets the value of a date field.default HttpFields.Mutableclear()static HttpFieldcomputeEnsure(HttpField ensure, String[] values, List<HttpField> fields) Compute ensure field with a multiple valuesstatic HttpFieldcomputeEnsure(HttpField ensure, List<HttpField> fields) Compute ensure field with a single valuedefault voidcomputeField(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 voidcomputeField(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 voidensureField(HttpField field) Ensure that specific HttpField exists when the field may not exist or may exist and be multi valued.static StringformatCsvExcludingExisting(QuotedCSV existing, String... values) iterator()default HttpFields.MutableSet a field.default HttpFields.MutableSet a field.default HttpFields.Mutabledefault HttpFields.Mutableput(HttpHeader header, String value) Set a field.default HttpFields.Mutableput(HttpHeader header, HttpHeaderValue value) default HttpFields.MutableputDateField(String name, long date) Sets the value of a date field.default HttpFields.MutableputDateField(HttpHeader name, long date) Sets the value of a date field.default HttpFields.MutableputLongField(String name, long value) Sets the value of an long field.default HttpFields.MutableputLongField(HttpHeader name, long value) Sets the value of an long field.default HttpFields.MutableRemove a field.default HttpFields.Mutableremove(EnumSet<HttpHeader> fields) default HttpFields.Mutableremove(HttpHeader header) Remove a field.Methods inherited from interface org.eclipse.jetty.http.HttpFields
asImmutable, asString, contains, contains, contains, contains, contains, contains, get, get, getCSV, getCSV, getDateField, getDateField, getField, getField, getField, getFieldNames, getFieldNamesCollection, getFields, getFields, getLongField, getLongField, getQualityCSV, getQualityCSV, getQualityCSV, getValues, getValuesList, getValuesList, isEqualTo, size, stream, takeAsImmutableMethods 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
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 soPreEncodedHttpFields 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
-
putDateField
Sets the value of a date field.- Parameters:
name- the field namedate- the field date value- Returns:
- this builder
-
putDateField
Sets the value of a date field.- Parameters:
name- the field namedate- the field date value- Returns:
- this builder
-
putLongField
Sets the value of an long field.- Parameters:
name- the field namevalue- the field long value- Returns:
- this builder
-
putLongField
Sets the value of an 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
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);- 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
-