I'm trying to use the HTTPRequest class to send a file to the browser. The goal is ultimately to create a pdf dynamically, then send it to the user. The PDF creation works fine, but I can't get SS to use the correct header when it sends the file to the browser. I've tried pretty much everything I can think of. As far as I understand, this should be all I need:
In the controller:
public function SendFileTest() {
return HTTPRequest::send_file(file_get_contents("../assets/test.pdf"), "test.pdf");
}
Looking at the HTTPRequest docs, it seems like SS should use the file extension to choose the correct mime type, but when I try this action in the browser it sends the file to the browser with a Content-Type of text/html (which displays the pdf as a bunch of gobbledygook in the browser window instead of giving the download prompt). So naturally I tried setting the headers manually, using the third parameter in the send_file() function, using the HTTPRequest::addHeader() function, and using straight up PHP header() function... all to no avail. SS still sends the content back with a Content-Type of text/html. What am I missing??
I've tried it with other file types as a test as well, nothin' doin'.
I know the HTTPRequest::send_file() works, since it's how the TableListField exports to csv. Any help would be much appreciated.