I am using Gralis 1.3.7. I am writing a controller that needs to get a PDF file from another server and return it to the client. I would like to do this in some reasonably efficient manner, such as the following:
class DocController {
def view = {
URL source = new URL("http://server.com?docid=${params.docid}");
response.contentType = 'application/pdf';
// Something like this to set the content length
response.setHeader("Content-Length", source.contentLength.toString());
response << source.openStream();
}
}
The problem I am having is figuring out how to set the content length of the response of my controller based on the information coming back from source
. I wasn't able to find the documentation on the URL class as enhanced by grails.
What's the best way to proceed?
Gene
EDITED: Fixed parameter values in setHeader
UPDATED 16 mar 2012 10:49 PST
UPDATED 19 March 2012 10:45 PST Moved follow-up to a separate question.