Fixes#4971 - Simplify Connection.upgradeFrom()/upgradeTo().
Now the upgrade-from connection produces a "floating" buffer
(not belonging to a pool), so that it can release the original buffer.
The upgrade-to connection is free to copy or store this "floating" buffer.
Strengthened ByteBufferPool behavior when releasing non-pooled
ByteBuffers: the buffer is now discarded.
Updated javadocs and all implementations.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Introduced:
* Request Request.headers(Consumer<HttpFields.Mutable>).
This allows applications to modify the headers, and chain calls.
It also delegates the precise semantic of put/add/remove/clear to HttpFields, so there is no API duplication.
* HttpRequest.header(HttpField) to efficiently add fields while normalizing the request (only used in implementation).
* HttpResponse.header(HttpField) to efficiently add fields while parsing the response (only used in implementation).
This pairs with HttpResponse.trailer(HttpField).
* HttpResponse.headers(Consumer<HttpFields.Mutable>) to modify the fields after they have been populated (only used in tests).
Removed:
* Request.[set,add,put,remove], replaced by headers(Consumer<HttpFields.Mutable>).
Deprecated:
* Request.header(String, String)
* Request.header(HttpHeader, String)
Both replaced by headers(Consumer<HttpFields.Mutable>) with clearer semantic for add/put/remove.
All the rest is code cleanup to remove the usage of the deprecated header() methods.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Made HttpURI, HttpFields and MetaData immutable. The first two follow the same builder pattern and MetaData is constructor injection only.
* Immutable version of HttpFields
Preserve API and usage of HttpFields class while providing a read only interface and immutable implementation.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable version of HttpFields
Use an ArrayList in HttpFields. While slightly slower than the array, it will mostly be used as a builder pattern for an Immutable
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable version of HttpFields
Fixed exception type.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable version of HttpFields
asImmutable method
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
Made HttpURIU immutable with a builder pattern.
MetaData immutable and working within http module.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
Fixes from review
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
Passing tests upto and including jetty-server
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
Cleanup of HttpURI.Builder API as suggested in PR.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
Added builder for MetaData.Request
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
more api fixes
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
WIP making HttpFiels itself immutable. Currently working up to jetty-servlet.
Need to consider if content-length really is meta data and how much and when can we trust it.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
WIP
Need to consider if content-length really is meta data and how much and when can we trust it. Also need to consider difference between h2 and h1 authority in metadata.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
jetty-client and jetty-servlet passing tests.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
Better align the style of immutability between `HttpFields` and `HttpURI`.
They both now have static build() and from() methods, plus Builder and Immutable implementations.
Potentially `Builder` could be renamed as `Mutable`
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
http2-server tests passed
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
http2-client tests passed
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
cleann build?
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
fix
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
more test fixes
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
Cleanups, mostly using EMPTY when appropriate.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
Cleanups, use immutable
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
No trailers for connect
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
Fix CONNECT path handling
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
fixed rewrite query handling
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
rename Builders to Muttables
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
misc cleanups
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
Revert to using arrays due to garbage generated by streams and iterators (12% of a simple benchmark!).
Even if this garbage is an artifact of the JIT being disabled by observation, it can hide other allocations, so best to just use simple arrays!
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
More optimizations and better test coverage.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable Metadata
various cleanups
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
More optimizations
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
review changes
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
changes after review:
+ less usage of Mutable
+ more usage of EMPTY
+ restored fragment handling
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
changes after review:
+ less usage of Mutable
+ less usage of asImmutable
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData WIP
changes after review:
+ less usage of Mutable
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
changes after review:
+ better handling of URI in ContextHandler
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
changes after review:
+ downcast in test to access mutable response headers.
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Immutable MetaData
changes after review:
+ use put instead of add for one time headers
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* private
Signed-off-by: Greg Wilkins <gregw@webtide.com>
* Introducing jetty-slf4j-impl
* Make Jetty use org.slf4j
* Removed most of org.eclipse.jetty.util.log classes
* Left org.eclipse.jetty.util.log.Log and
org.eclipse.jetty.util.log.Logger but as
simple bridge classes that are deprecated
* Migrated code using org.eclipse.jetty.util.log.StacklessLogging
to org.eclipse.jetty.logging.StacklessLogging found in
the jetty-slf4j-impl
* Moved logging start modules from jetty-util to jetty-home
* Simplified logging start modules
* Updated code that was using StdErrLog directly
* Updating module-info.java for org.slf4j
* removing org.eclipse.jetty.util.log.class references
* jetty-start supports manually declared default provider
+ and we use it to default "logging" to the "logging-jetty" provider
* Cleaning up jetty-maven-plugin and IT testing for Logging
* Using old slf4j for it testing
* Updating compiler config to show Xlint:exports warnings
* Updating console-capture and logging-noop
* Adding slf4j bridge (capture) jetty modules
* Updates to jetty logging module locations
* Changing reference to slf4j dependent mod
* Process requested enabled modules in topological order
* Limiting inclusions in shaded jetty-start
+ Also adding note to jetty-util classes that are used by
jetty-start
* Default logging level on baseline logging config is INFO (not DEBUG)
* Changing from system to server classes in logging
* Updating other modules to use new logging names
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Introduced Request.Content with a reactive model to provide
request content.
Introduced RequestContentAdapter to wrap ContentProviders
into Request.Content.
Updated implementation to use the reactive model rather than
the old pull model.
Reimplemented all ContentProviders in terms of Request.Content.
Converted most of the tests from ContentProvider to Request.Content.
Updated proxy servlets and documentation.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Added type parameter to methods that were using raw types.
Updated the implementation to use generics.
Deprecated static methods.
Updated usages.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
It is now possible to pass a `SslContextFactory.Client` to HttpProxy
so that it is possible to use a keystore for the proxy communication
and another keystore for the server communication.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Fixed setting of host/port in AbstractConnectorHttpClientTransport
and HttpProxy so that the creation of SSLEngine can use the proper
host/port pair, and can be subsequently used in TLS components.
Introduced SslContextFactory X509ExtendedKeyManagerWrapper and
X509ExtendedTrustManagerWrapper as utility classes used internally
and in tests.
The test case for this issue required 3 keystores, so other test
classes have been refactored to use the new keystores.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Introduced a Response.DemandedContentListener to explicitly separate
the will to request more content from the notification that the content
has been consumed.
Updated all transports to follow the new semantic: rather than waiting
for the callback to complete before delivering more content, now they
wait for the demand to be positive to deliver more content.
Since now the content may be unconsumed but there can be more demand,
all transport implementation had to be changed to use RetainableByteBuffer
to retain content buffers that were not consumed.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
* Issue #3806 async sendError
Avoid using isHandled as a test withing sendError as this can be
called asynchronously and is in a race with the normal dispatch of the
request, which could also be setting handled status.
The ErrorHandler was dispatching directly to a context from within
sendError. This meant that an async thread can call sendError and be
dispatched to within the servlet container at the same time that the
original thread was still dispatched to the container.
This commit fixes that problem by using an async dispatch for error
pages within the ErrorHandler. However, this introduces a new problem
that a well behaved async app will call complete after calling
sendError. Thus we have ignore complete ISEs for the remainder of
the current async cycle.
Fixed the closing of the output after calling sendError. Do not
close if the request was async (and thus might be dispatched to an
async error) or if it is now async because the error page itself is
async.
* updates from review
* better tests
* revert ignore complete
* added some TODOs
* more TODOs
* fixed rename
* cleanup ISE and more TODOs
* refactored to call sendError for uncaught exceptions rather than onError
* more of the refactor
* extra tests for sendError from completing state
Reworked HttpChannelState and sendError so that sendError is now
just a change of state. All the work is done in the ErrorDispatch
action, including calling the ErrorHandler. Async not yet working.
Additional tests
Converted ERRORED state to a separate boolean so it can be used for
both Sync and Async dispatches.
Removed ASYNC_IO state as it was just the same as DISPATCHED
The async onError listener handling is now most likely broken.
WIP making sendError simpler and more tests pass
WIP handling async and thrown exceptions
WIP passing tests
Improved thread handling
removed bad test
Implemented error dispatch on complete properly
more fixed tests
sendError state looks committed
- Added resetContent method to leave more non-content headers during sendError
- Fixed security tests
- simplified the non dispatch error page writing. Moved towards being able to write async
* fixed gzipHandlerTest
* Updated handling of timeout errors. According to servlet spec,
exceptions thrown from onTimeout should not be passed to onError, but
just logged and ignored:
If an exception is thrown while invoking methods in an AsyncListener,
it is logged and will not affect the invocation of any other AsyncListeners.
* This changes several tests.
* Dispatcher/ContextHandler changes for new ERROR dispatch handling. Feels a bit fragile!
* Fixed tests in jetty-servlets
* Fixed tests in jetty-proxy
* more test fixes
* Fixed head handling
reverted unnecessary changes
Improved reason handling
WIP on fully async error handling.
Simplified HttpChannelState state machines to allow for async actions
during completing
more WIP on fully async error handling.
sendError and completion are not both non-blocking, without using
a startAsync operation. However we are lacking unit tests that actually
exercise those code paths.
* Simplified name of states
Added test for async completion
* Cleanups and javadoc
* Cleanups and javadoc
* remove snake case
* feedback from review
* Write error page into fixed pooled buffer
Use the response to get/release a pooled buffer into which the error
page can be written. Make it a fixed sized buffer and if it overflows
then no error page is generated (first overflow turns off showstacks
to save space).
The ErrorHandler badly needs to be refactored, but we cannot change
API in jetty-9
* More test fixes for different error page format
* minor cleanups
* Cleanup from Review
* Fixed javadoc
* cleanups and simplifications
* Cleanup from Review
* renaming and some TODOs
* Cleanup from Review
* Checkstyle fixes
* Cleanup from Review
* Code cleanups and simplifications
* fixed debug
* Cleanup from Review
* Ensure response sent before server shutdown
* removed unnecessary optimisation
* fixed duplicate from merge
* Updates from review
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Fixes#250 - Implement HTTP CONNECT for HTTP/2.
Modified HTTP/2 implementation to support the CONNECT method.
Implemented semantic defined by RFC 8441.
Implemented section 8.3 of RFC 7540.
Introduced HTTP2Client.streamIdleTimeout.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
* Removing Legacy Method Separators
* Restyling branch `jetty-9.4.x`
* Applying changes highlighted by checkstyle
* Applying XML restyling
* Fixing XML codestyle for IntelliJ
* Fixing XML style mistakes
* Revert "Applying XML restyling"
* Updating checkstyle for XML codestyle
* Reformatting pom.xml files
* Fixed empty string from line wraps
* Update intellij style to not do expression relative formatting. Reformatted code based on that.
* Increasing line split on Eclipse IDE Formatter to 512
* Restoring setting on internal default value.
+ IntelliJ will not export settings on things that set to their
internal default values.
We want to keep those values as a hedge against future default
value changes in future releases of IntelliJ.
* Fixing intellij codestyle
* do not allow single line simple methods
* misc checkstyle fixes
* re-exported with correct name and all values
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
+ StringUtil.replace()
+ StringUtil.replaceFirst()
+ StringUtil.sanitizeFileSystemPath()
Change existing usages of String.replace() to either
use new StringUtil.replace() or other methods elsewhere
that better suit that specific need.
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
+ Deprecated B64Code
+ All code that isn't B64CodeTest is now using java.util.Base64
+ B64CodeTest is updated to confirm change to java.util.Base64
is possible without change in behavior. Just have to make
sure you use the appropriate Encoder / Decoder for the task
at hand (default vs mime vs url)
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
+ Updating to jetty-test-helper 4.2.1 with new Net.class
+ Assume.assumeTrue(Net.isIpv6InterfaceAvailable());
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
+ Updating to jetty-test-helper 3.1.1 with new Net.class
+ Assume.assumeTrue(Net.isIpv6InterfaceAvailable());
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
* exclude ipv6 test as currently failing on kubernetes, using junit tag and ci profile activated via Jenkinsfile
Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
* upgrade surefire to 3.0.0-M3
Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
Introduced SslContextFactory subclasses Client and Server.
Replaced all usages of SslContextFactory with either Client or Server
as required.
Refactored configuration checking so that warnings are not emitted
when non necessary.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
+ Any schedulers created are named (for ease of debug) and daemon
so they do not stop the JVM exiting.
+ If the server.doStart() fails, it calls server.doStop to ensure
connectors are stopped, ports are free etc.
+ cleanup of addBean handling of scheduler in proxy
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Introduced `HttpClientTransportDynamic` to be able to switch transport dynamically.
Refactored other transports and HttpDestination, removing now unnecessary classes.
Introduced ProxyProtocolClientConnectionFactory and used it for testing.
Updated OSGi tests now that jetty-client depends on jetty-alpn-client.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Modified jetty-client content decoding to be fully non-blocking;
this allows for a better backpressure and less usage of the buffer
pool.
Modified GZIPContentDecoder to aggregate decoded ByteBuffers in
a smarter way that avoids too many data copies and pollution of
the buffer pool with intermediate size buffers.
Removed duplicate test GZIPContentDecoderTest.
Improved javadocs and improved AsyncMiddleManServlet
to release buffers used by the GZIPContentDecoder.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Reviewed module-info.java files.
For those that have a "requires static" added a comment about
why the dependency is optional.
Rearranged directives in alphabetical order.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Introduced ClientConnector and refactored HttpClient transports,
removing duplicated code that was connect() to a remote host.
Refactored also HTTP2Client to reference ClientConnector.
Refactored tests accordingly to the changes introduced in the
implementations.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Updating SslContextFactory configuration for tests, since
the change in the default endPointIdentificationAlgorithm
makes the test failing as the certificates are not valid
for the local host, which is different depending on where
the tests are run (locally, jenkins).
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Introduced ClientConnector and refactored HttpClient transports,
removing duplicated code that was connect() to a remote host.
Refactored also HTTP2Client to reference ClientConnector.
Refactored tests accordingly to the changes introduced in the
implementations.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
* Updated module-info.java to reference the "jetty.servlet.api" module.
* Updated POMs to reference the o.e.j.toolchain:jetty-servlet-api artifact.
* Removed references to jetty-schemas.jar.
* Updated attribute "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern"
to match the new Jetty Servlet API jar.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Fixes#2978 - Add module-info to relevant Jetty modules.
Added module-info.java for Jetty modules that are not test modules.
Moved jetty-http test utility classes to new module "jetty-http-tools".
Removed generation of test-jar from websocket-core.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
* Cleanup the dump implementation
* improved the clarity of utility methods for dump and updated most dump methods
* fixed upgrade filter dump
* Improved dump after review
* Moved dumpObjects to Dumpable
* implemented dumpBeans with dumpObjects
* less verbose dump
* Dump streams
* fixed dump test
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
+ Changes needed for new Junit 5
+ Migrating from Vintage junit API to Jupiter junit API
+ Relies on SNAPSHOT jetty-test-helper
- this will be a formal release once this issue has been
resolved satisfactory
+ Have jenkins always pull latest SNAPSHOT for each build
+ Adding jetty.snapshots repository
+ Using surefire 2.22.0 per advice from junit
+ Ensuring <reuseForks>true</reuseForks> to work around issue junit-team/junit5#801
+ Disabling <forkMode>always</forkMode> in maven-surefire-plugin
due to bug https://github.com/junit-team/junit5/issues/801
+ OSGi tests must remain at vintage due to PaxExam
+ Moving from vintage TestingDir to jupiter WorkDir
+ Fixing imports to use jupiter, not vintage
+ Migrating vintage ExpectedException to jupiter assertThrows
+ Migrating vintage TestName to jupiter TestInfo
+ Migrating @RunWith(Parameterized.class)
to @ParameterizedTest with Argument Sources
+ Migrating assertTrue(val.contains(needle))
to assertThat(val, containsString(needle))
+ Aligning junit versions per recommendations from @sormuras
+ Adjusting parameter order change for assertEquals()
+ Test LifeCycle Annotation Migration
junit 4 | junit 5 / jupiter
------------ | -----------
@Before | @BeforeEach
@After | @AfterEach
@BeforeClass | @BeforeAll
@AfterClass | @AfterAll
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
+ Changes needed for new Junit 5
+ Migrating from Vintage junit API to Jupiter junit API
+ Relies on SNAPSHOT jetty-test-helper
- this will be a formal release once this issue has been
resolved satisfactory
+ Have jenkins always pull latest SNAPSHOT for each build
+ Adding jetty.snapshots repository
+ Using surefire 2.22.0 per advice from junit
+ Ensuring <reuseForks>true</reuseForks> to work around issue junit-team/junit5#801
+ Disabling <forkMode>always</forkMode> in maven-surefire-plugin
due to bug https://github.com/junit-team/junit5/issues/801
+ OSGi tests must remain at vintage due to PaxExam
+ Moving from vintage TestingDir to jupiter WorkDir
+ Fixing imports to use jupiter, not vintage
+ Migrating vintage ExpectedException to jupiter assertThrows
+ Migrating vintage TestName to jupiter TestInfo
+ Migrating @RunWith(Parameterized.class)
to @ParameterizedTest with Argument Sources
+ Migrating assertTrue(val.contains(needle))
to assertThat(val, containsString(needle))
+ Aligning junit versions per recommendations from @sormuras
+ Adjusting parameter order change for assertEquals()
+ Test LifeCycle Annotation Migration
junit 4 | junit 5 / jupiter
------------ | -----------
@Before | @BeforeEach
@After | @AfterEach
@BeforeClass | @BeforeAll
@AfterClass | @AfterAll
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
`AsyncMiddleManServlet.Transparent` class should extend `AsyncMiddleManServlet`
so the consumers can override the `newServerResponseContentTransformer` &
`newServerResponseContentTransformer` to provide their own ContentTransformer.
The way it is structured right now makes it impossible to use
`AsyncMiddleManServlet.Transparent` servlet as a middle man servlet.
Signed-off-by: Assim Deodia <assim.deodia@gmail.com>