It has been brought up in #1639, that it would be nice if the API of libp2p-request-response would offer ResponseChannel::send(response) instead of RequestResponse::send_response(channel, response). The advantage is obviously that one does not need to have access to the RequestResponse behaviour in order to send responses, i.e. one can distribute the ResponseChannels received from inbound requests in the application and send responses "from anywhere". Since RequestResponse::send_response currently needs no access to any state of the RequestResponse behaviour (contrary to RequestResponse::send_request), this would be easy to do. The main concern is one of future-proofness, i.e. if RequestResponse::send_response should later need access to RequestResponse state, the change may potentially be not backward-compatible or at least require more effort (i.e. it may be possible to do such a change without breaking the public API if the ResponseChannel that the behaviour exposes contains another oneshot channel whose receiving end is kept by the RequestResponse behaviour; once resolved (i.e. the response is send) it would forward the response to the oneshot channel whose receiving end is in the InboundUpgrade). Thus, if we change the API to offer ResponseChannel::send(response) and later need access to RequestResponse state, that would require some more indirection or a breaking change to the API. This issue is about weighing the pros/cons of providing ResponseChannel::send(response) vs the loss of flexibility in how sending of responses is implemented internally and gathering opinions on this matter.
It has been brought up in #1639, that it would be nice if the API of
libp2p-request-responsewould offerResponseChannel::send(response)instead ofRequestResponse::send_response(channel, response). The advantage is obviously that one does not need to have access to theRequestResponsebehaviour in order to send responses, i.e. one can distribute theResponseChannels received from inbound requests in the application and send responses "from anywhere". SinceRequestResponse::send_responsecurrently needs no access to any state of theRequestResponsebehaviour (contrary toRequestResponse::send_request), this would be easy to do. The main concern is one of future-proofness, i.e. ifRequestResponse::send_responseshould later need access toRequestResponsestate, the change may potentially be not backward-compatible or at least require more effort (i.e. it may be possible to do such a change without breaking the public API if theResponseChannelthat the behaviour exposes contains anotheroneshotchannel whose receiving end is kept by theRequestResponsebehaviour; once resolved (i.e. the response is send) it would forward the response to theoneshotchannel whose receiving end is in theInboundUpgrade). Thus, if we change the API to offerResponseChannel::send(response)and later need access toRequestResponsestate, that would require some more indirection or a breaking change to the API. This issue is about weighing the pros/cons of providingResponseChannel::send(response)vs the loss of flexibility in how sending of responses is implemented internally and gathering opinions on this matter.