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

Review Jetty-12 DelayedHandler #9051

Open
gregw opened this issue Dec 13, 2022 · 6 comments
Open

Review Jetty-12 DelayedHandler #9051

gregw opened this issue Dec 13, 2022 · 6 comments
Assignees

Comments

@gregw
Copy link
Contributor

gregw commented Dec 13, 2022

Jetty version(s)
12

Enhancement Description
Jetty-12 has generalized the previous jetty delayed dispatch mechanism. Currently there are Handlers that can delay dispatch until:

  • some content is available
  • form content has been read and converted to a form
  • multipart content has been asynchronously read and converted to parts.

However, it is possible that a deployment might need multiples of these behaviors and it is undesirable to have 3 such handlers stacked up. Thus we should consider refactoring so that there is a single DelayedHandler that can optionally perform various types of delay depending on content-type.

Furthermore, whilst the downstream handling of forms appears to have been updated to use any form read by this handler, the same has not been done for multiparts. The same pattern of looking for the processed content in the request attributes should be applied to parts.

@gregw
Copy link
Contributor Author

gregw commented Dec 14, 2022

I have a draft of this, but it is waiting for #9035 to be merged

@gregw
Copy link
Contributor Author

gregw commented Dec 23, 2022

#9056 has improved the implementation and merged the multiple handlers into a single one.
However, the API for extending it is not satisfactory and more thought is needed, so this issue should remain open until a better API is developed.

@gregw
Copy link
Contributor Author

gregw commented Dec 23, 2022

@sbordet Currently the problematic API is:

    protected DelayedProcess newDelayedProcess(boolean contentExpected, String contentType, MimeTypes.Type mimeType, Handler handler, Request request, Response response, Callback callback)

So first question: Should this handle be able to delay for non-content related purposes? We have no real use-cases, but we do have a test case for that, hence the need to pass contentExpected.

A good first simplification could be to rename the handler to DelayedContentHandler and to remove this parameter, so that if there is no content, then there is never any delay:

    protected DelayedProcess newDelayedProcess(String contentType, MimeTypes.Type mimeType, Handler handler, Request request, Response response, Callback callback)

We are passing both contentType and mimeType so we can switch efficiently on the later to find cases for known types, but we also need the former so we can extract a boundary from it for multipart.
It is a 1 liner to get the mimeType from the contentType, so perhaps we just move that into the method ?:

    protected DelayedProcess newDelayedProcess(String contentType, Handler handler, Request request, Response response, Callback callback)

Alternately, we could have a DelayedProcessFactory pattern:

    protected DelayedProcessFactory getDelayedProcessFactory(String contentType);
    interface DelayedProcessFactory
    {
        DelayedProcess newDelayedProcess(Handler handler, Request request, Response response, Callback callback);
    }

But multipart and other delays would need to wrap the factory to remember the boundary. I'm not sure the extensibility needs of this class justify a factory.

On balance, I think the version that just takes the String content-type is a good simplification, so long as we agree that this handler only delays content and no other reason?

gregw added a commit that referenced this issue Dec 23, 2022
…9056)


* Improved javadoc
* Refactored ThreadLimitHandler to avoid lambda creation and to always execute
* Refactored DelayedHandler to avoid lambda creation and to execute only if needed
* added modules for the DelayedHandler

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Co-authored-by: Simone Bordet <simone.bordet@gmail.com>
@gregw gregw self-assigned this Feb 2, 2023
@joakime joakime removed this from Jetty 12.0.3 Oct 11, 2023
Copy link

github-actions bot commented Feb 3, 2024

This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@github-actions github-actions bot added the Stale For auto-closed stale issues and pull requests label Feb 3, 2024
@sbordet sbordet removed the Stale For auto-closed stale issues and pull requests label Feb 3, 2024
@gregw gregw removed the Jetty 12 label May 1, 2024
@gregw
Copy link
Contributor Author

gregw commented May 26, 2024

@sbordet I'm bumping this to 12.1.0 and think we should consider re-introducing the built in HTTP/1 delayed dispatch (on by default) and making this handler less general purpose.

@gregw
Copy link
Contributor Author

gregw commented Jul 22, 2024

@sbordet @lorban @lachlan-roberts I'm going to reintroduce delayed dispatch to HttpConnection. Can you guys look at doing the same for h2 and h3. I think the DelayedHandler should then only be used for asynchronously reading entire contents before dispatch (probably renamed)

gregw added a commit that referenced this issue Nov 17, 2024
Fix #9051 with EagerContentHandler to replace DelayedHandler

The make the EagerContentHandler.RetainedContentLoader work efficiently this PR adjusted the buffering strategy of h1, h2 and h3 to keep and reuse a retained buffer until it is mostly full.

Also fixed several bugs in XmlConfiguration:

 + A Set could not be used with a builder style method (kind of missing feature more than a bug)
 + If a property element was used in a Set it could only be a string and the type element was ignored.
 + When trying to find a native match, the vClass local variable was overwritten with the native TYPE being tried. This affected subsequent match attempts using the wrong vClass

---------

Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
Signed-off-by: gregw <gregw@webtide.com>
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Co-authored-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
Co-authored-by: Simone Bordet <simone.bordet@gmail.com>
Co-authored-by: Ludovic Orban <lorban@bitronix.be>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants