com.HttpServiceRequest.sendFileResponse

Sends an HTTP response with the data contained in a file.

Syntax

sendFileResponse(
   code INTEGER,
   description STRING,
   filename STRING )
  1. code specifies the status code of the response.
  2. description specifies the description of the response.
  3. filename specifies the path of the file containing the data to be send.

Usage

The sendFileResponse() method performs the HTTP response by sending the status (code) and description (description), followed by the headers previously set and the data contained in the specified file as body.

The code returned ​can be a value between 100 and 999. You can send any code in this range. This provides support for the status codes returned by HTTP, WebDAV, other Request for Comments (RFC) codes, etc. The following determines how the description is handled:
  • If the code is recognized (as one of the standards) and the description is NULL, the code standard description is sent to the client.
  • If the code is not recognized, the description you provide is added. If you do not provide a description, a default, "No Message", is sent to the client as information about the code.
Note:

It is important for the server to return a status code, following the HTTP standards, otherwise the client may fail to interpret the response. For instance, if the request is malformed, the server is expected to send an HTTP response with the code of 400 (Bad Request).

For more details about HTTP response codes, see HTTP status codes (wikipedia).

If not defined by the programmer, the HTTP headers are automatically set as follows:

  • Content-Type is defined based on the filename extension. If the file extension is not recognized, Content-Type defaults to application/octet-stream.
    Note:

    File extensions to Content-Type mapping can be customized in the file $FGLDIR/lib/wse/mime.cfg.

  • Content-Disposition is set with the base name of the given filename as follows: attachment; filename="basename".
For example, when calling the method as follows:
CALL server.sendFileResponse( 200, NULL, "/opt/myapp/resources/logo.jpg" )
The resulting HTTP headers of the response will look like:
Content-Type: image/jpeg
Content-Disposition: attachment; filename="logo.jpg"

In HTTP 1.1, if the body size is greater than 32k, the response will be sent in several chunks of the same size.

New incoming requests can be retrieved again with the com.WebServiceEngine.GetHTTPServiceRequest() method.

In case of error, the method throws an exception and sets the status variable. Depending on the error, a human-readable description of the problem is available in the sqlca.sqlerrm register. See Error handling in GWS calls (status).

The int_flag variable is checked during GWS API call to handle program interruptions, for more details, see Interruption handling in GWS calls (int_flag)