GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — HTTP2: Ensure HTTP2 preface is always send as first message (also on … · netty/netty@cfcbf0e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http2/src/main/java/io/netty/handler/codec/http2
    • Http2ConnectionHandler.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
+31-18Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ public void register(ChannelHandlerContext ctx, CompletionHandler<Void> handler)
490490

491491
@Override
492492
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, CompletionHandler<Void> handler) {
493-
ctx.bind(localAddress, handler);
493+
// Ensure we send the preface before we notify the bind promise as the user might try to write
494+
// directly in the listener attached to the promise and we need to ensure the preface is always the first
495+
// thing that is written.
496+
ctx.bind(localAddress, new PrefaceSendListener(ctx, handler));
494497
}
495498

496499
@Override
@@ -499,23 +502,7 @@ public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, Sock
499502
// Ensure we send the preface before we notify the connect promise as the user might try to write
500503
// directly in the listener attached to the promise and we need to ensure the preface is always the first
501504
// thing that is written.
502-
ctx.connect(remoteAddress, localAddress, new CompletionHandler<>() {
503-
@Override
504-
public void success(Void result) {
505-
try {
506-
byteDecoder.sendPrefaceIfNeeded(ctx);
507-
} catch (Throwable e) {
508-
handler.failure(e);
509-
return;
510-
}
511-
handler.success(result);
512-
}
513-
514-
@Override
515-
public void failure(Throwable cause) {
516-
handler.failure(cause);
517-
}
518-
});
505+
ctx.connect(remoteAddress, localAddress, new PrefaceSendListener(ctx, handler));
519506
}
520507

521508
@Override
@@ -1042,4 +1029,30 @@ private void doClose() {
10421029
}
10431030
}
10441031
}
1032+
1033+
private final class PrefaceSendListener implements CompletionHandler<Void> {
1034+
private final ChannelHandlerContext ctx;
1035+
private final CompletionHandler<Void> handler;
1036+
1037+
PrefaceSendListener(ChannelHandlerContext ctx, CompletionHandler<Void> handler) {
1038+
this.ctx = ctx;
1039+
this.handler = handler;
1040+
}
1041+
1042+
@Override
1043+
public void success(Void result) {
1044+
try {
1045+
byteDecoder.sendPrefaceIfNeeded(ctx);
1046+
} catch (Throwable e) {
1047+
handler.failure(e);
1048+
return;
1049+
}
1050+
handler.success(result);
1051+
}
1052+
1053+
@Override
1054+
public void failure(Throwable cause) {
1055+
handler.failure(cause);
1056+
}
1057+
}
10451058
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.