-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking changes: The native part of one-nio now links and works only with OpenSSL 3 (tested on OpenSSL versions 3.0 and 3.2). The OpenSSL library file must have name libssl.so.3. Major changes: Added support for Kernel TLS, including sendfile Added support for TLS early data (TLS1.3 0-RTT) Added ability to export encryption keys (SSL keylog) Added support for SSL certificate compression (RFC8879) Added ability to use an external cache for SSL sessions Added ability to constrain selectors used by an acceptor Added ability to use a single acceptor thread for all sockets Added support for server-sent events in one.nio.http.HttpClient Also various fixes and optimizations.
- Loading branch information
Showing
66 changed files
with
3,968 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2024 LLC VK | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package one.nio.http; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A source of server side emitted events | ||
* | ||
* @see <a href="https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events">HTML Standard: 9.2 Server-sent events</a> | ||
* @see HttpClient#openEvents(Request, int) | ||
*/ | ||
public interface EventSource<D> extends Closeable | ||
{ | ||
/** | ||
* Waits for the next SSE and returns an event. The method can block for a long time ( determined by server ). | ||
* It is essential to check for null and {@link Event#isEmpty()} before processing | ||
* | ||
* @return the next event from the stream or null, if stream was closed by either party | ||
* @throws IOException an I/O exception occurred | ||
* @throws HttpException an incorrect HTTP request received | ||
*/ | ||
Event<D> poll( ) throws IOException, HttpException; | ||
|
||
/** | ||
* A single Server Sent Event, received from peer. | ||
*/ | ||
interface Event<D> | ||
{ | ||
/** | ||
* No name, id and data in event ( only comment ) | ||
* | ||
* @return true, if the event has no name, id and data. false, otherwise | ||
*/ | ||
boolean isEmpty(); | ||
|
||
/** | ||
* an SSE event name | ||
* | ||
* @return the event name | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* an SSE event id. this can be used to request events starting from specified | ||
* | ||
* @return the event id | ||
* @see <a href="https://html.spec.whatwg.org/multipage/server-sent-events.html#the-last-event-id-header">HTML Standard: 9.2.4 The `Last-Event-ID` header</a> | ||
*/ | ||
String id(); | ||
|
||
/** | ||
* an SSE "data" line. | ||
* | ||
* @return the event data | ||
*/ | ||
D data(); | ||
|
||
|
||
/** | ||
* an SSE comment concatenated | ||
* | ||
* @return the event comment | ||
*/ | ||
String comment(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 LLC VK | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package one.nio.http; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A Response, which can poll for server emitted events. | ||
* Unlike regular {@link Response} this object must be close'd to | ||
* prevent resource leak. | ||
* <p> | ||
* The usage flow is as follows: | ||
* <ol> | ||
* <li>Call {@link HttpClient#openEvents(Request, int)}</li> | ||
* <li>Inspect the result code, if it is not OK process the error</li> | ||
* <li>Inspect the content-type, it must be text/event-stream; if it is not - process the response body - there will be no events</li> | ||
* <li>while ( ( event = poll() ) != null ) process( event )</li> | ||
* <li>call {@link #close()}</li> | ||
* <li>call {@link HttpClient#reopenEvents(Request, String, int)} with last processed {@link Event#id()} and go to p.2</li> | ||
* </ol> | ||
* | ||
* @see <a href="https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events">HTML Standard: 9.2 Server-sent events</a> | ||
* @see HttpClient#openEvents(Request, int) | ||
*/ | ||
public class EventSourceResponse extends Response implements EventSource<String> | ||
{ | ||
private EventSource<String> eventSource; | ||
|
||
public EventSourceResponse( String resultCode ) | ||
{ | ||
super( resultCode ); | ||
} | ||
|
||
@Override | ||
public Event<String> poll() throws IOException, HttpException | ||
{ | ||
return eventSource == null ? null : eventSource.poll(); | ||
} | ||
|
||
void setEventSource( EventSource<String> es ) { | ||
this.eventSource = es; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException | ||
{ | ||
if ( eventSource != null ) { | ||
eventSource.close(); | ||
eventSource = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.