aksdb / caddy-cgi

Common Gateway Interface plugin for the Caddy HTTP server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to do an nph option?

jum opened this issue · comments

Is it possible to add an nph option to enable scripts that perform their own header processing?

@jum Do you have a specific example CGI script that currently doesn't work? AFAIK you can already set headers from within CGI and they will simply be passed along.

I don't think this is feasible without a lot of effort. The whole handling of CGI scripts is done as a sub-set of HTTP, so we can't just "pass through" raw responses.

Why would this be necessary, though? The only advantage I can see is that you could write a custom HTTP <status> <text> line. You can still set the status with the Status header, though. All the other headers get passed through already as well.

Aside from that possible problem with the status header, the script you provided works for me:
image

That's a valid use-case, I have to admit. I'll look into it once more when I have time. I don't have high hopes for it though. In Go we have control over the outgoing stream by calling Flush() whenever we need to omit the buffer ... but there is no way (that I know of) to disable the buffer completely. Maybe I can rework / extend the CGI handler to flush whenever it read something from stdout of the running executable.

No promises yet. As usual, it's very likely technically possible, but may require too much rework to be worth it.

If (!) it turns out to work the way I expect, then it would likely be an option like "unbuffered" or something. So the header handling will stay the way it is now, but all output from the script would be passed along ASAP. We'll see 🙂

I have just tested it, and it works nicely. I simply removed the nph options from the perl code and added the unbuffered_output option for this particular script and I can see the trace route steps while they happen. Thank you.