feat: Add ability to POST an SSE request
Background
Recently, I'm working on an SSE client to Tencent LKE interface, which use a POST request and reply SSE AIGC content. ruby-eventsource is a good gem to handle SSE replies, but cannot send request via POST.
Solution
This PR add a new param payload to initialize method. Some behaviors will be changed if payload is set.
- Request will be sent via HTTP POST method with
payloadcontent - Reconnection is disabled to avoid duplicated POST
Thank you for your interest and contribution. I do not have the capacity to review this PR quite yet, but I will get to it ASAP.
i need this feature as well. when will it get merged? Thanks
Hi! I also am working on something that could really benefit from this feature, thanks ^^
Went ahead and added support for PUT method as well: https://github.com/launchdarkly/ruby-eventsource/pull/64
Can we get a review on both PRs @keelerm84 if possible so we can get these features out?
@Gao-Jun and @saada I have made some modifications to this PR.
Instead of inferring the method from the presence of a payload, we are making those 2 separately provided items. This is more inline with some of our other event source SDKs.
Additionally, the request payload can be either a simple static value, or the result of a executing some payload function.
In a separate PR, I will introduce the ability to disable the retry functionality, which I also think should be explicitly defined rather than inferred.
@keelerm84 Thank you for your work. In the origin PR, when a POST request is closed, reconnection is disabled. code And this is not included in the final commits. Should we add this feature, or add a flag to handle this?
@keelerm84 In the origin PR, when a POST request is closed, reconnection is disabled. code And this is not included in the final commits. Should we add this feature, or add a flag to handle this?
I had mentioned above I would make a separate PR for that. Sorry I didn't have time to do it previously, but I have just merged it here.