Skip to content

Commit

Permalink
Improve consistency in API of FormFields maxFields and maxLength
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Jan 15, 2025
1 parent 818a765 commit f31e256
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static Fields getFields(Request request)
* Calls to {@code onFields} and {@code getFields} methods are idempotent, and
* can be called multiple times, with subsequent calls returning the results of the first call.
* @param request The request to get or read the Fields from
* @param maxFields The maximum number of fields to accept or -1 for a default
* @param maxFields The maximum number of fields to accept or -1 for a default.
* @param maxLength The maximum length of fields or -1 for a default.
* @return the Fields
* @see #onFields(Request, Promise.Invocable)
Expand Down Expand Up @@ -213,8 +213,8 @@ public static void onFields(Request request, Charset charset, Promise.Invocable<
*
* @param request The request to get or read the Fields from
* @param charset The {@link Charset} of the request content, if previously extracted.
* @param maxFields The maximum number of fields to accept; or -1 for a default
* @param maxLength The maximum length of fields; or -1 for a default
* @param maxFields The maximum number of fields to accept; or -1 for a default.
* @param maxLength The maximum length of fields; or -1 for a default.
* @param promise The action to take when the FormFields are available.
*/
public static void onFields(Request request, Charset charset, int maxFields, int maxLength, Promise.Invocable<Fields> promise)
Expand Down Expand Up @@ -254,9 +254,7 @@ else if (attr instanceof Fields fields)
@Deprecated(forRemoval = true, since = "12.0.15")
public static CompletableFuture<Fields> from(Request request)
{
int maxFields = getContextAttribute(request.getContext(), FormFields.MAX_FIELDS_ATTRIBUTE, FormFields.MAX_FIELDS_DEFAULT);
int maxLength = getContextAttribute(request.getContext(), FormFields.MAX_LENGTH_ATTRIBUTE, FormFields.MAX_LENGTH_DEFAULT);
return from(request, maxFields, maxLength);
return from(request, -1, -1);
}

/**
Expand All @@ -271,18 +269,16 @@ public static CompletableFuture<Fields> from(Request request)
@Deprecated(forRemoval = true, since = "12.0.15")
public static CompletableFuture<Fields> from(Request request, Charset charset)
{
int maxFields = getContextAttribute(request.getContext(), FormFields.MAX_FIELDS_ATTRIBUTE, FormFields.MAX_FIELDS_DEFAULT);
int maxLength = getContextAttribute(request.getContext(), FormFields.MAX_LENGTH_ATTRIBUTE, FormFields.MAX_LENGTH_DEFAULT);
return from(request, charset, maxFields, maxLength);
return from(request, charset, -1, -1);
}

/**
* Find or create a {@link FormFields} from a {@link Content.Source}.
* @param request The {@link Request} in which to look for an existing {@link FormFields} attribute,
* using the classname as the attribute name, else the request is used
* as a {@link Content.Source} from which to read the fields and set the attribute.
* @param maxFields The maximum number of fields to be parsed or -1 for unlimited
* @param maxLength The maximum total size of the fields or -1 for unlimited
* @param maxFields The maximum number of fields to be parsed or -1 for a default.
* @param maxLength The maximum total size of the fields or -1 for a default.
* @return A {@link CompletableFuture} that will provide the {@link Fields} or a failure.
* @deprecated use {@link #onFields(Request, Charset, int, int, Promise.Invocable)} instead.
*/
Expand All @@ -298,14 +294,18 @@ public static CompletableFuture<Fields> from(Request request, int maxFields, int
* using the classname as the attribute name, else the request is used
* as a {@link Content.Source} from which to read the fields and set the attribute.
* @param charset the {@link Charset} to use for byte to string conversion.
* @param maxFields The maximum number of fields to be parsed or -1 for unlimited
* @param maxLength The maximum total size of the fields or -1 for unlimited
* @param maxFields The maximum number of fields to be parsed or -1 for a default.
* @param maxLength The maximum total size of the fields or -1 for a default.
* @return A {@link CompletableFuture} that will provide the {@link Fields} or a failure.
* @deprecated use {@link #onFields(Request, Charset, int, int, Promise.Invocable)} instead.
*/
@Deprecated(forRemoval = true, since = "12.0.15")
public static CompletableFuture<Fields> from(Request request, Charset charset, int maxFields, int maxLength)
{
if (maxFields < 0)
maxFields = getContextAttribute(request.getContext(), FormFields.MAX_FIELDS_ATTRIBUTE, FormFields.MAX_FIELDS_DEFAULT);
if (maxLength < 0)
maxLength = getContextAttribute(request.getContext(), FormFields.MAX_LENGTH_ATTRIBUTE, FormFields.MAX_LENGTH_DEFAULT);
return from(request, InvocationType.NON_BLOCKING, request, charset, maxFields, maxLength);
}

Expand All @@ -317,8 +317,8 @@ public static CompletableFuture<Fields> from(Request request, Charset charset, i
* {@link FormFields}, using the classname as the attribute name. If not found the attribute
* is set with the created {@link CompletableFuture} of {@link FormFields}.
* @param charset the {@link Charset} to use for byte to string conversion.
* @param maxFields The maximum number of fields to be parsed
* @param maxLength The maximum total size of the fields
* @param maxFields The maximum number of fields to be parsed or -1 for unlimited.
* @param maxLength The maximum total size of the fields or -1 for unlimited.
* @return A {@link CompletableFuture} that will provide the {@link Fields} or a failure.
*/
static CompletableFuture<Fields> from(Content.Source source, InvocationType invocationType, Attributes attributes, Charset charset, int maxFields, int maxLength)
Expand Down

0 comments on commit f31e256

Please sign in to comment.