B4J Question Server Filter - resp.SendError has no effect

Alexander Stolte

Expert
Licensed User
Longtime User
If the ServerFilter False Returns, then the client falls into the timeout for the connection instead of receiving my error code.

B4J Server Filter Code:
'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
If req.ContentLength > (3 * 1024 * 1024) Then
             resp.SendError(413,"file too large") '3mb
            Log("file too large")
             Return False
        End If
End Sub

The client then has a timeout after a short time, if the filter returns false:
B4A Client:
ResponseError. Reason: java.net.SocketTimeoutException: timeout, Response:
java.net.SocketTimeoutException: timeout
j.Response.StatusCode is "-1"

Why does this occur? I send an extra error code to identify the problem, but the client timeouts.
 

Alexander Stolte

Expert
Licensed User
Longtime User
What happens if you return True? It will probably work as you want it.
If i return True, then it works, but the filter is there to clarify in advance if the request is legitimate.
Then I don't understand the sense of the filter, if it returns a timeout with the return value "false" instead of my error code.
So the filter must return "True" and I must send the error code in the handler?
 
Upvote 0
Top