icing / mod_h2

HTTP/2 module for Apache httpd
https://icing.github.io/mod_h2/
Apache License 2.0
256 stars 41 forks source link

Server-sent events (SSE) mod_h2, and mod_cgi(d) #285

Closed cnlohr closed 1 month ago

cnlohr commented 1 month ago

This is likely not an issue with mod_h2, but it might be and I figured I'd ask here to see if I could get any pointers on how to dig further into it.

I'm currently trying to use HTTP/2 in a full-duplex configuration, which looks like it should be possible from curl's point of view, but even if not, apache is misbehaving.

I am currently using:

for i in $(seq 5); do date;   sleep 1; done  | curl --noproxy '*' -H "Transfer-Encoding: chunked" -H "Content-Type: text/event-stream" -X POST -T - --trace-ascii - --http2 https://myserver/test.cgi

and on the server, I'm using:

<Directory "....">
        AllowOverride None
        Options +ExecCGI
        AddHandler cgi-script .cgi
</Directory>

This does correctly create an HTTP/2 connection, then, apache invokes my .cgi script, and my .cgi script begins receiving input from the host, and it starts sending a reply, prefixed with:

    printf( "Transfer-Encoding: chunked\r\n" );
    printf( "Content-Type: text/event-stream\r\n\r\n" );
    fflush( stdout );

But, data appears to be queued up in Apache at start, and not passed back to the user. Which kind of makes sense for HTTP/1.1. But, for HTTP/2, it should be able to send the data to the user dynamically.

I have validated that the application is running properly on the server, and getting all input dynamically when it was sent. I also tried sending very large buffers in reply, to try to force through any buffering/caching, but that isn't it.

Any ideas on what I would have to do with Apache2 to tell it "no, really, don't buffer replies to the client"?

cnlohr commented 1 month ago

Hmm, I am trying to test from source, but for some reason, the same curl command now yields a HTTP/1.1 100 Continue instead of HTTP/2.

Do I have to do anything in my httpd.conf other than:

LoadModule http2_module modules/mod_http2.so
Protocols  http/1.1 h2c h2

Or should it "just work"

cnlohr commented 1 month ago

Also, side-note, it looks like the issue is probably mod_cgid, in that it blocks in cgi_handle_request then calls shutdown(sd,1) before moving onto cgi_handle_response. I am not sure where the best place to discuss that would be...

cnlohr commented 1 month ago

Ok, definitely looks like this issue is squarely in mod_cgid - I am not sure the etiquette for opening an ASF bug but I am giving it a shot. Should I close this issue or leave it until someone who knows what's what comes along?

https://bz.apache.org/bugzilla/show_bug.cgi?id=69367 - to leave bread crumbs for anyone else...

icing commented 1 month ago

If you find a mistake in mod_h2 in handling SSEs, we can reopen this. For now, I close.

cnlohr commented 1 month ago

Thanks!