Skip to content

Commit

Permalink
Cosmetics.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Feb 27, 2024
1 parent b2e8dee commit cc745c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,10 @@ public Parser(String boundary, MultiPartCompliance compliance, Listener listener
MultiPartCompliance.Violation.CR_LINE_TERMINATION,
MultiPartCompliance.Violation.BASE64_TRANSFER_ENCODING,
MultiPartCompliance.Violation.WHITESPACE_BEFORE_BOUNDARY
).forEach(viol ->
).forEach(violation ->
{
if (compliance.allows(viol))
LOG.debug("{} ignoring compliance {}: unable to allow() it.", this.getClass().getName(), viol.name());
if (compliance.allows(violation))
LOG.debug("{} ignoring violation {}: unable to allow it", getClass().getName(), violation.name());
});
}
reset();
Expand Down Expand Up @@ -1072,7 +1072,7 @@ else if (type != HttpTokens.Type.SPACE && type != HttpTokens.Type.HTAB)
HttpTokens.Token token = next(buffer);
if (token.getByte() != '-')
throw new BadMessageException("bad last boundary");
notifyEolViolations();
notifyEndOfLineViolations();
state = State.EPILOGUE;
}
case HEADER_START ->
Expand Down Expand Up @@ -1122,7 +1122,7 @@ else if (type != HttpTokens.Type.SPACE && type != HttpTokens.Type.HTAB)
if (LOG.isDebugEnabled())
LOG.debug("parse failure {} {}", state, BufferUtil.toDetailString(buffer), x);
buffer.position(buffer.limit());
notifyEolViolations();
notifyEndOfLineViolations();
notifyFailure(x);
}
}
Expand Down Expand Up @@ -1150,7 +1150,7 @@ private HttpTokens.Token next(ByteBuffer buffer)
if (!crFlag)
{
MultiPartCompliance.Violation violation = MultiPartCompliance.Violation.LF_LINE_TERMINATION;
addEolViolation(violation);
addEndOfLineViolation(violation);
if (!compliance.allows(violation))
throw new BadMessageException("invalid LF-only EOL");
}
Expand All @@ -1161,7 +1161,7 @@ private HttpTokens.Token next(ByteBuffer buffer)
if (crFlag)
{
MultiPartCompliance.Violation violation = MultiPartCompliance.Violation.CR_LINE_TERMINATION;
addEolViolation(violation);
addEndOfLineViolation(violation);
if (!compliance.allows(violation))
throw new BadMessageException("invalid CR-only EOL");
}
Expand All @@ -1172,7 +1172,7 @@ private HttpTokens.Token next(ByteBuffer buffer)
if (crFlag)
{
MultiPartCompliance.Violation violation = MultiPartCompliance.Violation.CR_LINE_TERMINATION;
addEolViolation(violation);
addEndOfLineViolation(violation);
if (!compliance.allows(violation))
throw new BadMessageException("invalid CR-only EOL");
}
Expand Down Expand Up @@ -1375,7 +1375,7 @@ private boolean parseContent(Content.Chunk chunk)
if (!crContent)
{
MultiPartCompliance.Violation violation = MultiPartCompliance.Violation.LF_LINE_TERMINATION;
addEolViolation(violation);
addEndOfLineViolation(violation);
if (!compliance.allows(violation))
throw new BadMessageException("invalid LF-only EOL");
}
Expand Down Expand Up @@ -1425,7 +1425,7 @@ private boolean parseContent(Content.Chunk chunk)
if (!crContent)
{
MultiPartCompliance.Violation violation = MultiPartCompliance.Violation.LF_LINE_TERMINATION;
addEolViolation(violation);
addEndOfLineViolation(violation);
if (!compliance.allows(violation))
throw new BadMessageException("invalid LF-only EOL");
}
Expand All @@ -1447,7 +1447,7 @@ private boolean parseContent(Content.Chunk chunk)
else
{
MultiPartCompliance.Violation violation = MultiPartCompliance.Violation.LF_LINE_TERMINATION;
addEolViolation(violation);
addEndOfLineViolation(violation);
if (!compliance.allows(violation))
throw new BadMessageException("invalid LF-only EOL");
}
Expand Down Expand Up @@ -1602,7 +1602,7 @@ private void notifyFailure(Throwable failure)
}
}

private void notifyEolViolations()
private void notifyEndOfLineViolations()
{
if (eols != null)
{
Expand All @@ -1614,7 +1614,7 @@ private void notifyEolViolations()
}
}

private void addEolViolation(MultiPartCompliance.Violation violation)
private void addEndOfLineViolation(MultiPartCompliance.Violation violation)
{
if (eols == null)
eols = EnumSet.of(violation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ private MultiPartFormData()
}

/**
* Get {@code multipart/form-data} parts using {@link MultiPartCompliance#RFC7578} behaviors.
* Returns {@code multipart/form-data} parts using {@link MultiPartCompliance#RFC7578}.
*/
public static CompletableFuture<Parts> from(Attributes attributes, String boundary, Function<Parser, CompletableFuture<Parts>> parse)
{
return from(attributes, MultiPartCompliance.RFC7578, ComplianceViolation.Listener.NOOP, boundary, parse);
}

/**
* Get {@code multipart/form-data} parts using arbitrary {@link MultiPartCompliance} behaviors and listeners.
* Returns {@code multipart/form-data} parts using the given {@link MultiPartCompliance} and listener.
*
* @param attributes the attributes where the futureParts are tracked
* @param compliance the compliance mode
Expand Down Expand Up @@ -651,9 +651,16 @@ public void onFailure(Throwable failure)
@Override
public void onViolation(MultiPartCompliance.Violation violation)
{
complianceListener.onComplianceViolation(new ComplianceViolation.Event(
compliance, violation, "multipart spec violation"
));
try
{
ComplianceViolation.Event event = new ComplianceViolation.Event(compliance, violation, "multipart spec violation");
complianceListener.onComplianceViolation(event);
}
catch (Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("failure while notifying listener {}", complianceListener, x);
}
}

private void fail(Throwable cause)
Expand Down

0 comments on commit cc745c7

Please sign in to comment.