Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #11253 - Cleanup ComplianceViolation behavior to allow Cookie / URI / MultiPart compliance to also receive listener events. #11254

Merged
merged 36 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a125dcf
Fixing comments
joakime Jan 8, 2024
0844436
Adding TODOs about possible HTTP/2 & HTTP/3 violations
joakime Jan 8, 2024
46b3d6a
Adding missing javadoc
joakime Jan 8, 2024
2167aa5
Issue #11253 - Cleanup ComplianceViolation behavior to allow Cookie /…
joakime Jan 8, 2024
b86a415
Revert change to jetty-logging.properties
joakime Jan 8, 2024
d8b5bb8
Fix javadoc typos
joakime Jan 11, 2024
c0d0021
Merge remote-tracking branch 'origin/jetty-12.0.x' into fix/12.0.x/co…
joakime Jan 15, 2024
3818664
Issue #11253 - Alternate approach with split ComplianceViolation.List…
joakime Jan 16, 2024
ab199ac
Merge remote-tracking branch 'origin/jetty-12.0.x' into fix/12.0.x/co…
joakime Jan 16, 2024
20e7e41
Fix HttpParserTest
joakime Jan 16, 2024
ee568b6
Cleanup implementation
joakime Jan 16, 2024
1e525b8
Do not use deprecated method in our own code
joakime Jan 17, 2024
c5eda63
Fix ComplianceViolations2616Test failures
joakime Jan 17, 2024
3182982
Fixing ee9/ee8 RequestTest
joakime Jan 17, 2024
f7e3441
Updates from review
joakime Jan 17, 2024
af2ef3c
WIP on cleanup of ComplianceViolation.Listener instantiation
gregw Jan 18, 2024
9cc8053
WIP on cleanup of ComplianceViolation.Listener instantiation
gregw Jan 18, 2024
607934d
WIP on cleanup of ComplianceViolation.Listener instantiation
gregw Jan 18, 2024
9a2643a
WIP on cleanup of ComplianceViolation.Listener instantiation
gregw Jan 18, 2024
7f1f08b
WIP on cleanup of ComplianceViolation.Listener instantiation
gregw Jan 18, 2024
3c631fa
Merge branch 'jetty-12.0.x' into fix/12.0.x/cookie-compliance-logging2
gregw Jan 20, 2024
3357919
javadoc
gregw Jan 20, 2024
9601204
Store listeners in AbstractConnector
gregw Jan 20, 2024
dc5de07
Cleanup and reorganization of Proposal 2
joakime Jan 22, 2024
cf1f776
Merge branch 'fix/12.0.x/cookie-compliance-logging3' into fix/12.0.x/…
joakime Jan 23, 2024
c266d16
updates from review
gregw Jan 23, 2024
cdf8fcd
updates from review
gregw Jan 23, 2024
d7ac0d9
Changes from review
joakime Jan 23, 2024
9c4c264
Merge remote-tracking branch 'origin/fix/12.0.x/cookie-compliance-log…
joakime Jan 23, 2024
b4f4003
Fixing build
joakime Jan 23, 2024
823b0a1
Revert RequestHandler change
joakime Jan 23, 2024
34a67e2
Support ComplianceViolation.Listener in ee10 multipart/form
joakime Jan 23, 2024
1177674
Correct since versions
joakime Jan 23, 2024
5e275dd
Rename HttpChannel.init() to .initialize()
joakime Jan 23, 2024
80f8322
avoid double allocation of compliance listener list
gregw Jan 24, 2024
fdc0cd8
Avoid request specific listener in cookie cache
gregw Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ default void onComplianceViolation(Event event)
* @param details the details
* @deprecated use {@link #onComplianceViolation(Event)} instead. Will be removed in Jetty 12.1.0
*/
@Deprecated(since = "12.0.5", forRemoval = true)
@Deprecated(since = "12.0.6", forRemoval = true)
default void onComplianceViolation(Mode mode, ComplianceViolation violation, String details)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public String getDescription()
* Also make sure that a {@link ComplianceViolation.CapturingListener} has been added as a bean to
* either the {@code Connector} or {@code Server} for the Attribute to be created.)
*/
@Deprecated(since = "12.0.5", forRemoval = true)
@Deprecated(since = "12.0.6", forRemoval = true)
public static final String VIOLATIONS_ATTR = ComplianceViolation.CapturingListener.VIOLATIONS_ATTR_KEY;

/**
Expand Down Expand Up @@ -370,6 +370,9 @@ public static void checkHttpCompliance(MetaData.Request request, HttpCompliance
HttpFields fields = request.getHttpFields();
for (HttpField httpField: fields)
{
if (httpField.getHeader() == null)
continue;

switch (httpField.getHeader())
{
case CONTENT_LENGTH ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,22 @@ private MultiPartFormData()
{
}

/**
* @deprecated use {@link #from(Attributes, ComplianceViolation.Listener, String, Function)} instead. This method will be removed in Jetty 12.1.0
*/
@Deprecated(since = "12.0.6", forRemoval = true)
public static CompletableFuture<Parts> from(Attributes attributes, String boundary, Function<Parser, CompletableFuture<Parts>> parse)
{
return from(attributes, ComplianceViolation.Listener.NOOP, boundary, parse);
}

public static CompletableFuture<Parts> from(Attributes attributes, ComplianceViolation.Listener listener, String boundary, Function<Parser, CompletableFuture<Parts>> parse)
{
@SuppressWarnings("unchecked")
CompletableFuture<Parts> futureParts = (CompletableFuture<Parts>)attributes.getAttribute(MultiPartFormData.class.getName());
if (futureParts == null)
{
futureParts = parse.apply(new Parser(boundary));
futureParts = parse.apply(new Parser(boundary, listener));
attributes.setAttribute(MultiPartFormData.class.getName(), futureParts);
}
return futureParts;
Expand Down Expand Up @@ -200,9 +209,6 @@ public static class Parser
{
private final PartsListener listener = new PartsListener();
private final MultiPart.Parser parser;
// TODO: it's a bit odd to hang onto a ComplianceViolation.Listener here.
// as that would require the user to pass it in. Maybe a List<Event> violations instead?
// that the ee10 layer could use?
private ComplianceViolation.Listener complianceViolationListener;
joakime marked this conversation as resolved.
Show resolved Hide resolved
private boolean useFilesForPartsWithoutFileName;
private Path filesDirectory;
Expand All @@ -213,8 +219,14 @@ public static class Parser
private Parts parts;

public Parser(String boundary)
{
this(boundary, null);
}

public Parser(String boundary, ComplianceViolation.Listener complianceViolationListener)
{
parser = new MultiPart.Parser(Objects.requireNonNull(boundary), listener);
this.complianceViolationListener = complianceViolationListener != null ? complianceViolationListener : ComplianceViolation.Listener.NOOP;
}

public CompletableFuture<Parts> parse(Content.Source content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private HttpChannel pollHttpChannel()
httpChannel = httpChannels.poll();
if (httpChannel == null)
httpChannel = httpChannelFactory.newHttpChannel(this);
httpChannel.init();
httpChannel.initialize();
return httpChannel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Runnable onRequest(HeadersFrame frame)
_requestMetaData = (MetaData.Request)frame.getMetaData();

// Grab freshly initialized ComplianceViolation.Listener here, no need to reinitialize.
ComplianceViolation.Listener listener = _httpChannel.getComponents().getComplianceViolationListener();
ComplianceViolation.Listener listener = _httpChannel.getComplianceViolationListener();
Runnable handler = _httpChannel.onRequest(_requestMetaData);
Request request = _httpChannel.getRequest();
listener.onRequestBegin(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Runnable onRequest(HeadersFrame frame)
requestMetaData = (MetaData.Request)frame.getMetaData();

// Grab freshly initialized ComplianceViolation.Listener here, no need to reinitialize.
ComplianceViolation.Listener listener = httpChannel.getComponents().getComplianceViolationListener();
ComplianceViolation.Listener listener = httpChannel.getComplianceViolationListener();
Runnable handler = httpChannel.onRequest(requestMetaData);
Request request = this.httpChannel.getRequest();
listener.onRequestBegin(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Runnable onRequest(HTTP3StreamServer stream, HeadersFrame frame)
{
// Create new metadata for every request as the local or remote address may have changed.
HttpChannel httpChannel = httpChannelFactory.newHttpChannel(new MetaData());
httpChannel.init();
httpChannel.initialize();
HttpStreamOverHTTP3 httpStream = new HttpStreamOverHTTP3(this, httpChannel, stream);
httpChannel.setHttpStream(httpStream);
stream.setAttachment(httpStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package org.eclipse.jetty.server;

import org.eclipse.jetty.http.ComplianceViolation;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.thread.Scheduler;
Expand Down Expand Up @@ -44,11 +43,4 @@ public interface Components
* @return A Map, which may be an empty map that discards all items.
*/
Attributes getCache();

/**
* @return A {@link ComplianceViolation.Listener} instance that has been
* {@link ComplianceViolation.Listener#initialize() initialized}
* for the current request cycle.
*/
ComplianceViolation.Listener getComplianceViolationListener();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import org.eclipse.jetty.http.ComplianceViolation;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.server.internal.HttpChannelState;
import org.eclipse.jetty.util.thread.Invocable;
Expand All @@ -37,13 +38,7 @@ public interface HttpChannel extends Invocable
ConnectionMetaData getConnectionMetaData();

/**
* @return the {@link Components} associated with this {@code HttpChannel}.
* @see Request#getComponents()
*/
Components getComponents();

/**
* Set the {@link HttpStream} to associate to this channel.
* Set the {@link HttpStream} to associate to this channel..
* @param httpStream the {@link HttpStream} to associate to this channel.
*/
void setHttpStream(HttpStream httpStream);
Expand Down Expand Up @@ -106,15 +101,41 @@ public interface HttpChannel extends Invocable
/**
* Recycle the HttpChannel, so that a new cycle of calling {@link #setHttpStream(HttpStream)},
* {@link #onRequest(MetaData.Request)} etc. may be performed on the channel.
* @see #init()
* @see #initialize()
*/
void recycle();

/**
* Initialize the HttpChannel when a new cycle of request handling begins.
* @see #recycle()
*/
void init();
void initialize();

/**
* @return the active {@link ComplianceViolation.Listener}
*/
ComplianceViolation.Listener getComplianceViolationListener();

/**
* @param request attempt to resolve the HttpChannel from the provided request
* @return the HttpChannel if found
* @throws IllegalStateException if unable to find HttpChannel
*/
static HttpChannel from(Request request)
{
while (true)
{
if (request instanceof Request.Wrapper wrapper)
request = wrapper.getWrapped();
else
break;
}
gregw marked this conversation as resolved.
Show resolved Hide resolved

if (request.getComponents() instanceof HttpChannel httpChannel)
return httpChannel;

throw new IllegalStateException("Unable to find HttpChannel from " + request);
}

/**
* <p>A factory for {@link HttpChannel} instances.</p>
Expand Down
Loading