Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for server-side trailer headers with chunk-encoded responses #141

Open
clemep-sios opened this issue Mar 5, 2021 · 0 comments
Open

Comments

@clemep-sios
Copy link

I am using Starman as the backend HTTP server for a PSGI app, and need to use a Trailer header, e.g.:

<Response Headers>
Trailer: X-Payload-Signature
<Response Body>
X-Payload-Signature: 330cce9978d4682f

Right now, Starman does not support trailer headers (https://tools.ietf.org/html/rfc7230#section-4.1.2) with chunk-encoded server responses.

Would there be any interest in a simple addition to support this?

A very rough idea for a patch (minimally tested, so far):

diff --git a/lib/Starman/Server.pm b/lib/Starman/Server.pm
index c2c6d77..468a778 100644
--- a/lib/Starman/Server.pm
+++ b/lib/Starman/Server.pm
@@ -550,8 +550,17 @@ sub _finalize_response {
                 }
                 _syswrite($conn, \$buffer);
             },
+            trailer => sub {
+                $self->{trailer} = shift;
+            },
             close => sub {
-                _syswrite($conn, \"0$CRLF$CRLF") if $chunked;
+                if ($chunked) {
+                    _syswrite($conn, \"0$CRLF");
+                    if (my $trailer = delete $self->{trailer}) {
+                        _syswrite($conn, \"$trailer$CRLF");
+                    }
+                    _syswrite($conn, \"$CRLF");
+                }
             };
     }
 }

I will work on a PR and unit tests, if there is interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant