KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Avoid Browsers attempting to download files instead of receiving pages
PRODUCT: 4D | VERSION: 6.7 | PLATFORM: Mac & Win
Published On: July 27, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

https://www.4d.com/support/tips01-666.htmlWe have recently seen code like the following:

GET HTTP HEADER(atWWWHeaderNames;atWWWHeaderValues)

$line:=Find in array(atWWWHeaderNames;"SomeParameter")
If ($line=-1)
$line:=Size of array(atWWWHeaderNames)+1
INSERT ELEMENT(atWWWHeaderNames;$line;1)
INSERT ELEMENT(atWWWHeaderValues;$line;1)
End if
atWWWHeaderNames{$line}:="SomeParameter"
atWWWHeaderValues{$line}:="RevisedValue"
SET HTTP HEADER(atWWWHeaderNames;atWWWHeaderValues)

It is completely unnecessary to send back every parameter sent by the browser. You should only send back to the browser values that you need to modify. The negative behavior observed from doing things this way is that when a form uses a POST command, if the next page sent uses this type code some browsers will attempt to download a file rather than show the page.

The specific array elements that appear to be causing the current problem are "Content-Transfer-Encoding" and "Content-Encoding." If you remove these two elements from the Names and Values array before the SET HTTP HEADER command the current problem appears to be solved. However, there is no guarantee that using the technique above won't break again in the future.

The following code would be a better solution:

` Declare someplace in the code before it is first needed
ARRAY TEXT(atNewHeaderNames;0)
ARRAY TEXT(atNewHeaderValues;0)


` Each time you need to check for a specific parameter
$ReviseHeader:=False

GET HTTP HEADER(atWWWHeaderNames;atWWWHeaderValues)

$line:=Find in array(atWWWHeaderNames;"SomeParameter")
If ($line=-1)
$ReviseHeader:=True
Else
If (atWWWHeaderValues{line}#"RevisedValue")
$ReviseHeader:=True
End if
End if

If ($ReviseHeader)
$size:=Size of array(atNewHeaderNames)+1
INSERT ELEMENT(atNewHeaderNames;$line;$size)
INSERT ELEMENT(atNewHeaderValues;$line;$size)
atNewHeaderNames{$line}:="SomeParameter"
atNewHeaderValues{$line}:="RevisedValue"
End if


` Finally just before you send the HTML page/blob
If (Size of array(atNewHeaderNames)>0)
SET HTTP HEADER(atNewHeaderNames;atNewHeaderValues)
End if