question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support HTTP/1.1 protocol upgrades

See original GitHub issue

We should implement user-requested protocol upgrades as specified by RFC 7230 section 6.7.

Use Cases

Eligibility

An HTTP/1 call is upgraded if all of the following are true:

  • The caller’s request includes an Upgrade header
  • The caller’s request includes a Connection header with the value upgrade
  • The server’s response includes an Upgrade header
  • The server’s response includes a Connection header with the value upgrade
  • The response code is 101.

On Upgrade

A successful upgrade changes the behavior of the HTTP response:

  • The ResponseBody is null.
  • The response has a non-null Streams object that carries the input and output stream. Note that the source and sink timeouts should work properly!
interface Streams {
  val source: BufferedSource
  val sink: BufferedSink
  fun cancel()
}
class Response {
  ...
  /** Non-null if this response is a successful upgrade ... */
  @get:JvmName("streams") val streams: Streams?
}

A successful upgrade has these side-effects:

  • The call timeout is immediately completed. (RealCall.timeoutEarlyExit())
  • The connection is forbidden from carrying new exchanges. (RealConnection.noNewExchanges())
  • The socket’s read timeout is disabled. (Socket.setSoTimeout())
  • If the call is asynchronous (Call.enqueue()), the call counts against Dispatcher limits until onResponse() returns.

I’ve used the class name Streams instead of UpgradedConnection or something feature-specific because I think we might be able to reuse this type for CONNECT calls.

Web Sockets

Can we migrate our internal web sockets code to use this? Ideally yes, though that shouldn’t block this from being released.

Event Listeners

Ideally we have well defined behavior for EventListeners on an upgraded connection. We need to decide whether to count bytes of the upgraded connection for the benefit of listeners.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
swankjessecommented, Sep 9, 2022

Yeah, this is something we want.

1reaction
gesellixcommented, Jan 4, 2022

@swankjesse thanks for coming back to this one!

It’s the same use case like for docker-java (Docker’s HTTP Hijacking), with the only difference that I’m maintaining yet another Java docker-client, based on OkHttp 4.x. You can find myself struggling with a hacky implementation.

I’m now trying to have a more generic implementation, based on Docker’s Swagger definition and more generated code - with the hijacking feature being one of the custom parts, obviously, and I didn’t want to copy the old hacky code over to the fresh implementation.

Maybe this one helps: I tried to implement integration test by copying the relevant code from Docker to a small utility. It’s certainly not ready for wide-spread use and it probably needs some polishing, but you might also have the problem of testing the hijacking client.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade - HTTP - MDN Web Docs - Mozilla
The HTTP 1.1 (only) Upgrade header can be used to upgrade an already established client/server connection to a different protocol (over the ...
Read more >
HTTP/1.1 Upgrade header - Wikipedia
The Upgrade header field is an HTTP header field introduced in HTTP/1.1. In the exchange, the client begins by making a cleartext request,...
Read more >
RFC 2817: Upgrading to TLS Within HTTP/1.1
Please refer to the current edition of the "Internet Official Protocol Standards" ... RFC 2817 HTTP Upgrade to TLS May 2000 HTTP/1.1 101...
Read more >
Upgrading to TLS Within HTTP/1.1
The Upgrade response header field advertises possible protocol upgrades a server MAY accept. In conjunction with the "426 Upgrade Required" ...
Read more >
HTTP Protocol Upgrade Mechanism explained
A protocol upgrade is initiated by using the Upgrade HTTP request header. It can be employed to transition from the current HTTP/1.1 connection ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found