From 5394f044d045eafa4b5f63e731f4469dd15a9b63 Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 4 Jan 2024 22:14:40 +0100 Subject: [PATCH] Support user-defined reason phrase Signed-off-by: jansupol --- README.md | 13 +++++++++++-- .../tyrus/client/TyrusClientEngineTest.java | 12 +++++++++++- .../grizzly/client/GrizzlyClientFilter.java | 3 ++- .../grizzly/server/GrizzlyServerFilter.java | 5 ++++- .../tyrus/core/TyrusUpgradeResponse.java | 7 +++++-- pom.xml | 18 +++++++++++++++++- .../glassfish/tyrus/spi/UpgradeResponse.java | 17 ++++++++++++----- .../test/standard_config/HandshakeTest.java | 14 +++++++++----- 8 files changed, 71 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8cf70135..dcf230be 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ for easy development of WebSocket applications.Eclipse Tyrus is also a Jakarta WebSocket 2.0 compatible implementation. WebSocket protocol defined by IETF -provides bi-directional communication between the server and the remote host. The +provides bidirectional communication between the server and the remote host. The pros are mainly the ability to communicate both ways, low latency and small -communication overhead. Therefore Tyrus and WebSocket in general are suitable for web +communication overhead. Therefore, Tyrus and WebSocket in general are suitable for web applications that require sending a huge volume of relatively small messages like online games or market ticker broadcasting. @@ -20,6 +20,15 @@ online games or market ticker broadcasting. Building Tyrus can be done using `mvn clean install`, but sometimes (such as for building 2.x from a tag) `mvn clean install -Pstaging` would be required. +## Tyrus Git Branches + +| branch | Jakarta Version | Tyrus Version | +|--------|---------------------------------|---------------| +| master | Java EE 8 / Jakarta EE 8 branch | Tyrus 1.x | +| 2.0.x | Jakarta EE 9 branch | Tyrus 2.0.x | +| 2.1.x | Jakarta EE 10 branch | Tyrus 2.1.x | +| 2.x | Jakarta EE 11 branch | Tyrus 2.2.x | + ## Licensing - [Eclipse Public License 2.0](https://projects.eclipse.org/license/epl-2.0) diff --git a/client/src/test/java/org/glassfish/tyrus/client/TyrusClientEngineTest.java b/client/src/test/java/org/glassfish/tyrus/client/TyrusClientEngineTest.java index d0672304..62cbf507 100644 --- a/client/src/test/java/org/glassfish/tyrus/client/TyrusClientEngineTest.java +++ b/client/src/test/java/org/glassfish/tyrus/client/TyrusClientEngineTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -443,6 +443,11 @@ public void setReasonPhrase(String reason) { } + @Override + public String getReasonPhrase() { + return null; + } + @Override public Map> getHeaders() { headers.put(HandshakeResponse.SEC_WEBSOCKET_ACCEPT, Collections.singletonList(serverKey)); @@ -468,6 +473,11 @@ public void setReasonPhrase(String reason) { } + @Override + public String getReasonPhrase() { + return null; + } + @Override public Map> getHeaders() { return headers; diff --git a/containers/grizzly-client/src/main/java/org/glassfish/tyrus/container/grizzly/client/GrizzlyClientFilter.java b/containers/grizzly-client/src/main/java/org/glassfish/tyrus/container/grizzly/client/GrizzlyClientFilter.java index bd6374f8..b8b7266b 100644 --- a/containers/grizzly-client/src/main/java/org/glassfish/tyrus/container/grizzly/client/GrizzlyClientFilter.java +++ b/containers/grizzly-client/src/main/java/org/glassfish/tyrus/container/grizzly/client/GrizzlyClientFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -396,6 +396,7 @@ private static UpgradeResponse getUpgradeResponse(HttpResponsePacket httpRespons } tyrusUpgradeResponse.setStatus(httpResponsePacket.getStatus()); + tyrusUpgradeResponse.setReasonPhrase(httpResponsePacket.getReasonPhrase()); return tyrusUpgradeResponse; } diff --git a/containers/grizzly-server/src/main/java/org/glassfish/tyrus/container/grizzly/server/GrizzlyServerFilter.java b/containers/grizzly-server/src/main/java/org/glassfish/tyrus/container/grizzly/server/GrizzlyServerFilter.java index f2e0f0bc..1bf58b93 100644 --- a/containers/grizzly-server/src/main/java/org/glassfish/tyrus/container/grizzly/server/GrizzlyServerFilter.java +++ b/containers/grizzly-server/src/main/java/org/glassfish/tyrus/container/grizzly/server/GrizzlyServerFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -281,6 +281,9 @@ private void write(FilterChainContext ctx, UpgradeResponse response) { ((HttpRequestPacket) ((HttpContent) ctx.getMessage()).getHttpHeader()).getResponse(); responsePacket.setProtocol(Protocol.HTTP_1_1); responsePacket.setStatus(response.getStatus()); + if (response.getReasonPhrase() != null) { + responsePacket.setReasonPhrase(response.getReasonPhrase()); + } // TODO // responsePacket.setReasonPhrase(response.getReasonPhrase()); diff --git a/core/src/main/java/org/glassfish/tyrus/core/TyrusUpgradeResponse.java b/core/src/main/java/org/glassfish/tyrus/core/TyrusUpgradeResponse.java index 5222361c..4f556ace 100644 --- a/core/src/main/java/org/glassfish/tyrus/core/TyrusUpgradeResponse.java +++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusUpgradeResponse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -52,10 +52,13 @@ public int getStatus() { /** * Get HTTP reason phrase. + *

+ * Warning: The Reason Phrase is removed from HTTP/2 and from Servlet 6. + *

* * @return reason phrase. */ -// @Override + @Override public String getReasonPhrase() { return reasonPhrase; } diff --git a/pom.xml b/pom.xml index 82fc7468..ca5487ce 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@