CGI library should give access to raw request body
I was trying to write a little CGI script that simply stencils out e-mail autoconfig as defined by Microsoft’s autodiscover protocol, however, that protocol requires the client to transmit its request as XML data via POST. Ruby’s CGI library appears to assume that one only ever needs HTML form data in POST requests, at least I see no obvious way from the documentation to gain access to the raw request body as it was written on $stdin as per section 4.2 of RFC 3857. I have thus to resort to handling everything manually with the CGI library, which is unfortunate, since I wanted to use the same CGI script for Mozilla’s e-mail autoconfig protocol as well, which works by doing a GET request with a query parameter (
?emailaddress=) against a similar endpoint. Since I don’t want to parse query parameters myself, and since I would like a uniform handling as far as possible, it’d be nice to have a method CGI.request_body that simply grants access to a copy of the content that the web server wrote on Ruby’s $stdin.
Simply reading $stdin before calling CGI.new doesn’t work, because the cgi library than sends a SIGTERM to the running Ruby process itself (why does it do that instead of raising an exception?).