Reputation: 6248
I want to handle some malicious request by not sending any kind of response in Flask.
In a route like:
@app.route("/something", methods=['POST'])
def thing():
return
Still returns an INTERNAL SERVER ERROR
with View function did not return a response
.
How do I formally send NO RESPONSE back to a client, i.e from an ajax call like so?
$.ajax({
url: "/something/",
method: "POST",
data: JSON.stringify({
"foo": "abc",
"bar": "123"
}),
success: function(resp) {
console.log(resp);
},
error: function(error) {
console.log(error); // this still gets called. I want it to hang.
}
})
Upvotes: 5
Views: 1101
Reputation: 123320
... I want it to hang.
What you probably want is to close the connection on the server side (since you need to free the resources) but don't want the client to realize that the connection is closed. You cannot do this from flask or any other web application since any close of the connection on the server will cause the OS kernel to send the FIN to the client and thus the client knows about the closing too.
I suggest instead that you issue a redirect to the client to a URL where the client just hangs: for example have some iptables DROP rule on port 8080 and then redirect the client to http://your.host:8080/
. Many clients will blindly follow such redirects and then hang (until they timeout) while trying to connect to this dead drop URL.
Upvotes: 9