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

Jetty 12 inserted handler in ee10 servlet context #9927

Merged
merged 32 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
825aae8
Added distro test for static content features.
gregw Jun 15, 2023
fe1da61
fix ee9 DefaultServlet to make it able to send static content that is…
lorban Jun 15, 2023
1b926cf
Fixed favicon.ico test
gregw Jun 16, 2023
12b7e7b
Disabled gzipHandler for ee10 demo
gregw Jun 16, 2023
8e23eab
Wrap context with gzipHandler for ee10 test
gregw Jun 16, 2023
d0395a9
Misc cleanups of servlet request/response wrappers to simplify them.
gregw Jun 16, 2023
6644ff4
Merge branch 'jetty-12.0.x' into jetty-12-ee10-late-servlet-wrap
gregw Jun 16, 2023
f76bd97
WIP
gregw Jun 16, 2023
f95c515
ServletChannel holds HttpOutput
gregw Jun 16, 2023
bb3c636
WIP
gregw Jun 16, 2023
38bfa48
WIP
gregw Jun 19, 2023
e3b46f5
WIP
gregw Jun 19, 2023
38b2eb7
WIP
gregw Jun 19, 2023
eb03490
WIP
gregw Jun 19, 2023
df6aa6b
WIP
gregw Jun 19, 2023
d813b48
Testing gzip in context
gregw Jun 19, 2023
6de0808
Revert "Disabled gzipHandler for ee10 demo"
gregw Jun 19, 2023
305d824
improved comments
gregw Jun 19, 2023
9158757
updates from review
gregw Jun 19, 2023
55a483b
fixed javadoc
gregw Jun 19, 2023
be6fe3b
updates from review
gregw Jun 20, 2023
a75395a
update javadoc
gregw Jun 20, 2023
f871894
fixed websocket remove extension
gregw Jun 20, 2023
c7d140a
Added info interfaces
gregw Jun 20, 2023
7d2ad66
Added info interfaces
gregw Jun 20, 2023
539c172
Merge branch 'jetty-12.0.x' into jetty-12-ee10-late-servlet-wrap
gregw Jun 20, 2023
c0b6550
updates from review
gregw Jun 20, 2023
6407e18
fixed merge
gregw Jun 21, 2023
1a7ee80
Merge remote-tracking branch 'origin/jetty-12.0.x' into jetty-12-ee10…
gregw Jun 21, 2023
bea21c3
Merge remote-tracking branch 'origin/jetty-12.0.x' into jetty-12-ee10…
gregw Jun 21, 2023
58338f0
Merge branch 'jetty-12.0.x' into jetty-12-ee10-late-servlet-wrap
gregw Jun 22, 2023
21da275
updates from review
gregw Jun 22, 2023
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 @@ -1204,6 +1204,167 @@ else if (ensured > 0)
// return a merged header with missing ensured values added
return new HttpField(ensure.getHeader(), ensure.getName(), v.toString());
}

/**
* A wrapper of {@link HttpFields}.
*/
class Wrapper implements Mutable
{
private final Mutable _fields;

public Wrapper(Mutable fields)
{
_fields = fields;
}

/**
* Called when a field is added (including as part of a put).
* @param field The field being added.
* @return The field to add, or null if the add is to be ignored.
*/
public HttpField onAddField(HttpField field)
gregw marked this conversation as resolved.
Show resolved Hide resolved
{
return field;
}

/**
* Called when a field is removed (including as part of a put).
* @param field The field being removed.
* @return True if the field should be removed, false otherwise.
*/
public boolean onRemoveField(HttpField field)
{
return true;
}

@Override
public HttpFields takeAsImmutable()
{
return Mutable.super.takeAsImmutable();
}

@Override
public int size()
{
// This impl needed only as an optimization
return _fields.size();
}

@Override
public Stream<HttpField> stream()
{
// This impl needed only as an optimization
return _fields.stream();
}

@Override
public Mutable add(HttpField field)
{
// This impl needed only as an optimization
if (field != null)
{
field = onAddField(field);
if (field != null)
return _fields.add(field);
}
return this;
}

@Override
public ListIterator<HttpField> listIterator()
{
ListIterator<HttpField> i = _fields.listIterator();
return new ListIterator<>()
{
HttpField last;

@Override
public boolean hasNext()
{
return i.hasNext();
}

@Override
public HttpField next()
{
return last = i.next();
}

@Override
public boolean hasPrevious()
{
return i.hasPrevious();
}

@Override
public HttpField previous()
{
return last = i.previous();
}

@Override
public int nextIndex()
{
return i.nextIndex();
}

@Override
public int previousIndex()
{
return i.previousIndex();
}

@Override
public void remove()
{
if (last != null && onRemoveField(last))
{
last = null;
i.remove();
}
}

@Override
public void set(HttpField field)
{
if (field == null)
{
if (last != null && onRemoveField(last))
{
last = null;
i.remove();
}
}
else
{
if (last != null && onRemoveField(last))
{
field = onAddField(field);
if (field != null)
{
last = null;
i.set(field);
}
}
}
}

@Override
public void add(HttpField field)
{
if (field != null)
{
field = onAddField(field);
if (field != null)
{
last = null;
i.add(field);
}
}
}
};
}
}
}

/**
gregw marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -1391,8 +1552,12 @@ public HttpField getField(int index)
public int hashCode()
{
int hash = 0;
for (int i = _fields.length; i-- > 0; )
hash ^= _fields[i].hashCode();
for (int i = _size; i-- > 0; )
{
HttpField field = _fields[i];
if (field != null)
hash ^= field.hashCode();
}
return hash;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static Stream<HttpFields.Mutable> mutables()
return Stream.of(
HttpFields.build(),
HttpFields.build(0),
new HttpFields.Mutable.Wrapper(HttpFields.build()),
new HttpFields.Mutable()
{
private final HttpFields.Mutable fields = HttpFields.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,8 @@ private WelcomeAction processWelcome(Request request) throws IOException
return null;

String contextPath = request.getContext().getContextPath();

if (LOG.isDebugEnabled())
LOG.debug("welcome={}", welcomeTarget);

WelcomeMode welcomeMode = getWelcomeMode();

welcomeTarget = switch (welcomeMode)
{
case REDIRECT, REHANDLE -> HttpURI.build(request.getHttpURI())
Expand All @@ -601,6 +598,9 @@ private WelcomeAction processWelcome(Request request) throws IOException
case SERVE -> welcomeTarget;
};

if (LOG.isDebugEnabled())
LOG.debug("welcome {} {}", welcomeMode, welcomeTarget);

return new WelcomeAction(welcomeTarget, welcomeMode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ public boolean handle(Request request, Response response, Callback callback) thr
if (Request.as(request, GzipRequest.class) != null)
return next.handle(request, response, callback);

String path = Request.getPathInContext(request);
boolean tryInflate = getInflateBufferSize() >= 0 && isPathInflatable(path);
boolean tryDeflate = _methods.test(request.getMethod()) && isPathDeflatable(path) && isMimeTypeDeflatable(request.getContext().getMimeTypes(), path);
String pathInContext = Request.getPathInContext(request);
boolean tryInflate = getInflateBufferSize() >= 0 && isPathInflatable(pathInContext);
boolean tryDeflate = _methods.test(request.getMethod()) && isPathDeflatable(pathInContext) && isMimeTypeDeflatable(request.getContext().getMimeTypes(), pathInContext);

// Can we skip looking at the request and wrapping request or response?
if (!tryInflate && !tryDeflate)
Expand Down Expand Up @@ -624,15 +624,15 @@ protected boolean isPathDeflatable(String requestURI)
/**
* Test if the provided Request URI is allowed to be inflated based on the Path Specs filters.
*
* @param requestURI the request uri
* @param pathInContext the request path in context
* @return whether decompressing is allowed for the given the path.
*/
protected boolean isPathInflatable(String requestURI)
protected boolean isPathInflatable(String pathInContext)
{
if (requestURI == null)
if (pathInContext == null)
return true;

return _inflatePaths.test(requestURI);
return _inflatePaths.test(pathInContext);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ private enum StreamSendState
private final HandlerInvoker _handlerInvoker = new HandlerInvoker();
private final ConnectionMetaData _connectionMetaData;
private final SerializedInvoker _serializedInvoker;
private final Attributes _requestAttributes = new Attributes.Lazy();
private final ResponseHttpFields _responseHeaders = new ResponseHttpFields();
private Thread _handling;
private boolean _handled;
Expand Down Expand Up @@ -157,7 +156,6 @@ public void recycle()
_streamSendState = StreamSendState.SENDING;

// Recycle.
_requestAttributes.clearAttributes();
_responseHeaders.reset();
_handling = null;
_handled = false;
Expand Down Expand Up @@ -741,6 +739,7 @@ public static class ChannelRequest implements Attributes, Request
private final MetaData.Request _metaData;
private final AutoLock _lock;
private final LongAdder _contentBytesRead = new LongAdder();
private final Attributes _attributes = new Attributes.Lazy();
private HttpChannelState _httpChannelState;
private Request _loggedRequest;
private HttpFields _trailers;
Expand Down Expand Up @@ -777,46 +776,45 @@ public long getContentBytesRead()
@Override
public Object getAttribute(String name)
{
HttpChannelState httpChannel = getHttpChannelState();
if (name.startsWith("org.eclipse.jetty"))
{
if (Server.class.getName().equals(name))
return httpChannel.getConnectionMetaData().getConnector().getServer();
return getConnectionMetaData().getConnector().getServer();
if (HttpChannelState.class.getName().equals(name))
return httpChannel;
return getHttpChannelState();
// TODO: is the instanceof needed?
// TODO: possibly remove this if statement or move to Servlet.
if (HttpConnection.class.getName().equals(name) &&
getConnectionMetaData().getConnection() instanceof HttpConnection)
return getConnectionMetaData().getConnection();
}
return httpChannel._requestAttributes.getAttribute(name);
return _attributes.getAttribute(name);
}

@Override
public Object removeAttribute(String name)
{
return getHttpChannelState()._requestAttributes.removeAttribute(name);
return _attributes.removeAttribute(name);
}

@Override
public Object setAttribute(String name, Object attribute)
{
if (Server.class.getName().equals(name) || HttpChannelState.class.getName().equals(name) || HttpConnection.class.getName().equals(name))
return null;
return getHttpChannelState()._requestAttributes.setAttribute(name, attribute);
return _attributes.setAttribute(name, attribute);
}

@Override
public Set<String> getAttributeNameSet()
{
return getHttpChannelState()._requestAttributes.getAttributeNameSet();
return _attributes.getAttributeNameSet();
}

@Override
public void clearAttributes()
{
getHttpChannelState()._requestAttributes.clearAttributes();
_attributes.clearAttributes();
}

@Override
Expand All @@ -837,7 +835,7 @@ public ConnectionMetaData getConnectionMetaData()
return _connectionMetaData;
}

HttpChannelState getHttpChannelState()
private HttpChannelState getHttpChannelState()
{
try (AutoLock ignore = _lock.lock())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public void close()

/**
* A shared reusable Blocking source.
* TODO Review need for this, as it is currently unused.
*/
public static class Shared
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public interface ServerUpgradeResponse extends Response

void addExtensions(List<ExtensionConfig> configs);

void removeExtensions(List<ExtensionConfig> configs);

void setExtensions(List<ExtensionConfig> configs);
}
Loading