ncarlier / webhookd

A very simple webhook server launching shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make "data : " Prefix toggleable or remove entirely

movd opened this issue · comments

Hi, thanks for this excellent tool!

It would be great if the "data : " prefix sent in response to GET requests could be toggleable or removed.

With this, this tool could be used to output Prometheus Metrics :)

Current behavior:

$ curl -XGET -s 'localhost:8080/metrics.sh'
data: some_custom_metric_generated_in_a_shell_script{hook_name="metrics"} 1

Behavior suggested by this issue

$ curl -XGET -s 'localhost:8080/metrics.sh'
some_custom_metric_generated_in_a_shell_script{hook_name="metrics"} 1

Code producing the current behavior:

fmt.Fprintf(w, "data: %s\n\n", msg) // Send SSE response

Hi, thank you for the interest shown in this project!

I understand your need. Your concern is not really about the prefix but about the Server Sent Event (SSE) usage.
The prefix is part of the Event Stream format.
What the project needs is the possibility to activate/deactivate the SSE support.

Regards

Thanks for the feedback. I learned something new. Until now, I didn't know about the Event Stream format. I will close my PR and work on a toggle to deactivate SSE if needed.

Thinking about your problem, I think we can solve this with a cooler way than a feature flipping flag.
Maye we should use the Accept HTTP header. Only activate SSE if the Accept request header is text/event-stream.
I have to test, curl, and several Browsers to verify that this header is properly set when expecting a SSE response.

As a result, using the Accept header is a perfect choice for streaming protocol.
Thank you very much for this issue.

Thanks for the neat solution! I already tested it using the edge container image. Do you plan on creating a new release for this addition?

Yes but maybe with another addition...