Skip to content

Commit 1f5de3d

Browse files
authored
Correctly send http end when no upgrade header (#1626)
1 parent d74e5c3 commit 1f5de3d

5 files changed

Lines changed: 134 additions & 7 deletions

File tree

  • runtime/binding-ws/src
  • specs/binding-ws.spec/src
    • main/scripts/io/aklivity/zilla/specs/binding/ws/streams/network/advise/client.sent.no.upgrade
    • test/java/io/aklivity/zilla/specs/binding/ws/streams/network

runtime/binding-ws/src/main/java/io/aklivity/zilla/runtime/binding/ws/internal/stream/WsServerFactory.java

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ public MessageConsumer newStream(
210210
doHttpBegin(sender, originId, routedId, newReplyId, 0L, 0L, 0, traceId, authorization, affinity,
211211
hs -> hs.item(h -> h.name(":status").value("400"))
212212
.item(h -> h.name("connection").value("close")));
213-
doHttpEnd(sender, originId, routedId, newReplyId, traceId);
213+
doWindow(sender, originId, routedId, initialId, 0, 0, 0, traceId, authorization, 0, 0);
214+
doHttpEnd(sender, originId, routedId, newReplyId, 0L, 0L, 0, traceId, authorization);
214215
newStream = (t, b, o, l) -> {};
215216
}
216217
else if (key != null &&
@@ -1487,18 +1488,55 @@ private void doHttpEnd(
14871488
long originId,
14881489
long routedId,
14891490
long streamId,
1490-
long traceId)
1491+
long sequence,
1492+
long acknowledge,
1493+
int maximum,
1494+
long traceId,
1495+
long authorization)
14911496
{
14921497
final EndFW end = endRW.wrap(writeBuffer, 0, writeBuffer.capacity())
1493-
.originId(originId)
1494-
.routedId(routedId)
1495-
.streamId(streamId)
1496-
.traceId(traceId)
1497-
.build();
1498+
.originId(originId)
1499+
.routedId(routedId)
1500+
.streamId(streamId)
1501+
.sequence(sequence)
1502+
.acknowledge(acknowledge)
1503+
.maximum(maximum)
1504+
.traceId(traceId)
1505+
.authorization(authorization)
1506+
.build();
14981507

14991508
receiver.accept(end.typeId(), end.buffer(), end.offset(), end.sizeof());
15001509
}
15011510

1511+
private void doWindow(
1512+
MessageConsumer receiver,
1513+
long originId,
1514+
long routedId,
1515+
long streamId,
1516+
long sequence,
1517+
long acknowledge,
1518+
int maximum,
1519+
long traceId,
1520+
long authorization,
1521+
long budgetId,
1522+
int padding)
1523+
{
1524+
final WindowFW window = windowRW.wrap(writeBuffer, 0, writeBuffer.capacity())
1525+
.originId(originId)
1526+
.routedId(routedId)
1527+
.streamId(streamId)
1528+
.sequence(sequence)
1529+
.acknowledge(acknowledge)
1530+
.maximum(maximum)
1531+
.traceId(traceId)
1532+
.authorization(authorization)
1533+
.budgetId(budgetId)
1534+
.padding(padding)
1535+
.build();
1536+
1537+
receiver.accept(window.typeId(), window.buffer(), window.offset(), window.sizeof());
1538+
}
1539+
15021540
private Flyweight.Builder.Visitor visitWsDataEx(
15031541
int flags)
15041542
{

runtime/binding-ws/src/test/java/io/aklivity/zilla/runtime/binding/ws/internal/streams/server/AdvisoryIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,13 @@ public void shouldReceiveClientSentChallenge() throws Exception
9191
{
9292
k3po.finish();
9393
}
94+
95+
@Test
96+
@Configuration("server.yaml")
97+
@Specification({
98+
"${net}/client.sent.no.upgrade/client" })
99+
public void shouldReceiveClientEndWhenNoUpdate() throws Exception
100+
{
101+
k3po.finish();
102+
}
94103
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Copyright 2021-2024 Aklivity Inc.
3+
#
4+
# Aklivity licenses this file to you under the Apache License,
5+
# version 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. You may obtain a copy of the License at:
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
#
16+
17+
property key ${ws:handshakeKey()}
18+
19+
connect "zilla://streams/net0"
20+
option zilla:window 8192
21+
option zilla:transmission "half-duplex"
22+
23+
write zilla:begin.ext ${http:beginEx()
24+
.typeId(zilla:id("http"))
25+
.header(":method", "GET")
26+
.build()}
27+
28+
connected
29+
30+
read zilla:begin.ext ${http:beginEx()
31+
.typeId(zilla:id("http"))
32+
.header(":status", "400")
33+
.header("connection", "close")
34+
.build()}
35+
36+
read closed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright 2021-2024 Aklivity Inc.
3+
#
4+
# Aklivity licenses this file to you under the Apache License,
5+
# version 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. You may obtain a copy of the License at:
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
#
16+
17+
accept "zilla://streams/net0"
18+
option zilla:window 8192
19+
option zilla:transmission "half-duplex"
20+
accepted
21+
22+
read zilla:begin.ext ${http:beginEx()
23+
.typeId(zilla:id("http"))
24+
.header(":method", "GET")
25+
.build()}
26+
27+
write zilla:begin.ext ${http:beginEx()
28+
.typeId(zilla:id("http"))
29+
.header(":status", "400")
30+
.header("connection", "close")
31+
.build()}
32+
33+
connected
34+
35+
write close

specs/binding-ws.spec/src/test/java/io/aklivity/zilla/specs/binding/ws/streams/network/AdvisoryIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,13 @@ public void shouldReceiveClientSentChallenge() throws Exception
7272
{
7373
k3po.finish();
7474
}
75+
76+
@Test
77+
@Specification({
78+
"${net}/client.sent.no.upgrade/client",
79+
"${net}/client.sent.no.upgrade/server" })
80+
public void shouldReceiveClientEndWhenNoUpdate() throws Exception
81+
{
82+
k3po.finish();
83+
}
7584
}

0 commit comments

Comments
 (0)