Skip to content

Conversation

gesellix
Copy link
Collaborator

@gesellix gesellix commented Jul 28, 2025

See https://docs.docker.com/reference/api/engine/version/v1.51/#tag/Container/operation/ContainerAttach

The following RFC paragraph might be relevant: https://datatracker.ietf.org/doc/html/rfc9110#section-7.8-15

A client cannot begin using an upgraded protocol on the connection until it has completely sent the request message (i.e., the client can't change the protocol it is sending in the middle of a message). If a server receives both an Upgrade and an Expect header field with the "100-continue" expectation (Section 10.1.1), the server MUST send a 100 (Continue) response before sending a 101 (Switching Protocols) response.

Copy link
Contributor

@squarejesse squarejesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this is right yet. I think as-is the exchange considers the request body stream to be closed, and that will cause us grief when the Socket.source is closed.

@gesellix gesellix force-pushed the gesellix.0728.upgrade_with_body branch from cba33c1 to 5060bd1 Compare July 29, 2025 11:51
@gesellix gesellix changed the title Allow HTTP/1.1 Upgrades with RequestBody Allow HTTP/1.1 Upgrades with empty RequestBody Jul 29, 2025
Comment on lines 243 to 242
"SocketSinkStart",
"SocketSinkEnd",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these events should appear after the RequestBodyEnd event.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is that if it’s an upgrade request, we emit a Content-Length: 0 header but ignore the request body, and emit zero events related to it

@gesellix gesellix force-pushed the gesellix.0728.upgrade_with_body branch from 5060bd1 to c568801 Compare July 29, 2025 11:58
/**
* Invoked just prior to sending bytes on the socket. Will only be invoked for upgraded connections.
*
* The connection is implicit, and will generally relate to the last [connectionAcquired] event.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we strengthen this guarantee? Maybe we should pass the connection itself to this method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the checks which ensure that *End happens after *Start, leveraging this generic check?

private var bytesReceived = 0L
private var invokeStartEvent = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class needs to know if it’s being used for the socket or a regular request body

Comment on lines 243 to 242
"SocketSinkStart",
"SocketSinkEnd",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is that if it’s an upgrade request, we emit a Content-Length: 0 header but ignore the request body, and emit zero events related to it

@gesellix gesellix force-pushed the gesellix.0728.upgrade_with_body branch from c568801 to 50ea587 Compare July 31, 2025 17:45
@gesellix gesellix force-pushed the gesellix.0728.upgrade_with_body branch from 50ea587 to bec3270 Compare August 1, 2025 19:53
@gesellix gesellix force-pushed the gesellix.0728.upgrade_with_body branch from bec3270 to df8743f Compare August 1, 2025 23:48
@gesellix gesellix force-pushed the gesellix.0728.upgrade_with_body branch from df8743f to 1c94596 Compare August 2, 2025 00:09
@@ -143,11 +147,10 @@ class Exchange(
fun peekTrailers(): Headers? = codec.peekTrailers()

fun upgradeToSocket(): Socket {
isSocket = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this one fail due to race conditions?

@gesellix gesellix requested a review from swankjesse August 4, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants