interrupt the file sending if the file size over the quota...some errors here...

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Tue Jan 15 13:46:52 CET 2013


Am 15.01.2013 10:46, schrieb Levi Nie:
> i want to interrupt the file sending. but i can't change the client. so i
> need change the server.
> All things go well, but the message i wanna response seem not work.

Ahem, what? It doesn't work, so does it sit on the couch all day?


> is the self.transport.loseConnection() (the last line) blocking the
> messages?
> in fact, i work on Cumulus(nimbus project) which based on twisted. And i
> use s3cmd as the client.

I'm wondering if questions concerning twisted don't have a better forum. 
In any case, I can only comment on the general approach. For that, there 
are two things you can do:

1. When receiving the the request header, you have a content length. If 
that exceeds the allowed amount, shutdown() receiving and send an 
according HTTP response before closing the connection.
2. If the data exceeds the amount advertised by the content length, 
close the connection and discard the request. If you want to be nice, 
send an according response before closing, but I personally wouldn't go 
to that effort for broken HTTP clients.

Concerning the question why your client hangs, it could also be the 
sending. If you try to send something before receiving the full request, 
client and server could enter a deadlock where each side waits for the 
other to receive some data. For that reason, you should shutdown() 
receiving in such a case.

HTH

Uli




More information about the Python-list mailing list