What makes %Plug.Conn{} a "conn"?

Doesn’t it actually represent a single HTTP request? It seems to me that it gets created for every request, not just for every new TCP connection.

It’s an abstraction. It doesn’t matter whether a particular TCP connection is reused or not. It’s an abstraction that represents the current request’s connection.

I wonder though if %Plug.Req{} would have been a more fitting name for the struct …

The thing about the conn is that it’s actually impure. There are various operations on it that directly affect the actual TCP connection, like read_body. This mix of pure and impure has its issues but either way, conn makes it clear that you’re dealing with the actual active connection.

Req suffers from the problem that the conn is also where you place response data.

Is there a practical question in here or is this just musings?

1 Like

Just musings.