SEND HTTP RAW DATA

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 2004


SEND HTTP RAW DATA (data{; *})

ParameterTypeDescription
dataBLOBHTTP data to send
**Send chunked

Description

The SEND HTTP RAW DATA command lets the 4D Web server send "raw" HTTP data, which can be chunked. It only operates in non-contextual mode.

The data parameter contains the two standard parts of an HTTP response, i.e. Header and Body. The data are sent without prior formatting by the server. However, 4th Dimension carries out a basic check of the response header and body in order to make sure that they are valid:

If the header is incomplete or does not comply with the HTTP protocol specifications, 4th Dimension will change it accordingly.

If the HTTP request is incomplete, 4th Dimension adds the missing information. If, for instance, you want to redirect the request, you must write:

   HTTP/1.1 302
   Location: http://...

If you only pass:

   Location: http://...

4th Dimension will complete the request by adding HTTP/1.1 302.

The optional * parameter lets you specify that the response will be sent "chunked". The cutting up of responses into chunks can be useful when the server sends a response without knowing its total length (if, for instance, the response has not yet been generated). All HTTP/1.1-compatible browsers accept chunked responses.

If you pass the * parameter, the Web server will automatically include the transfer-encoding: chunked field in the header of the response, if necessary (you can handle the response header manually if you so desire). The remainder of the response will also be formatted in order to respect the syntax of the chunked option. Chunked responses contain a single header and an undefined number of body "chunks".

All the SEND HTTP RAW DATA statements that follow the execution of SEND HTTP RAW DATA(data;*) within the same method will be considered as part of the response (regardless of whether they contain the * parameter). The server puts an end to the chunked send when the method execution is terminated.

Note: If the Web client does not support HTTP/1.1, 4th Dimension will automatically convert the response into an HTTP/1.0-compatible format (the data sent will not be chunked). However, in this case, the result may not correspond to your wishes. It is therefore recommended to check whether the Web browser supports HTTP/1.1 and to send an appropriate response. To do so, you can use a method such as:

   C_BOOLEAN($0)
   ARRAY TEXT(arFields;0)
   ARRAY TEXT(arValues;0)
   GET HTTP HEADER(arFields;arValues)
   $0:=False
   If (Size of array(arValues)>=3)
      If (Position("HTTP/1.1";arValues{3})>0)
         $0:=True   ` The browser supports HTTP/1.1; $0 returns True
      End if
   End if

Combined with the new GET HTTP BODY command and other commands of the "Web Server" theme, this command completes the range of tools available to 4D developers in order to entirely customize the processing of incoming and outgoing HTTP connections. These different tools are shown in the following diagram:

Example

This example illustrates the use of the chunked option with the SEND HTTP RAW DATA command. The data (a sequence of numbers) are sent in 100 chunks generated on the fly in a loop. Keep in mind that the header of the response is not explicitly set: the SEND HTTP RAW DATA command will send it automatically and insert the transfer-encoding: chunked field into it since the * parameter is used.

   C_LONGINT($cpt)
   C_BLOB($my_blob)
   C_TEXT($output)

   For ($cpt;1;100)
      $output:="["+String($cpt)+"]"
      TEXT TO BLOB($output;$my_blob;Text without length)   
      SEND HTTP RAW DATA($my_blob;*) 
   End for

See Also

GET HTTP BODY, GET HTTP HEADER.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next