interrupt the file sending if the file size over the quota...someerrors here...

L

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.
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.

here is the my code:

def headerReceived(self,line):
pycb.log(logging.INFO, "===== def headerReceived of cumulus.py")
http.HTTPChannel.headerReceived(self,line)
pycb.log(logging.INFO, "===== self.length is %s"%self.length)

header, data = line.split(':', 1)
header = header.lower()
data = data.strip()
if header=='authorization':
self.authorization=data


if self.length and self.authorization:
user_id = self.authorization.split(':')[0].split()[1].strip()
user = pycb.config.auth.get_user(user_id)

pycb.log(logging.INFO, "===== user who put this object is
%s"%user)

remaining_quota = user.get_remaining_quota()
pycb.log(logging.INFO, "===== remaining_quota is
%s"%remaining_quota)
quota_check=self.length-remaining_quota
pycb.log(logging.INFO, "=====
quota_check=self.length-remaining_quota of cumulus.py")

if quota_check>0:
requestId = str(uuid.uuid1()).replace("-", "")
ex=cbException('AccountProblem')

m_msg = "HTTP/1.1 %s %s\r\n" % (ex.httpCode, ex.httpDesc)
self.transport.write(m_msg)

m_msg = "%s: %s\r\n" % (('x-amz-request-id', requestId))
self.transport.write(m_msg)
#req.setHeader('x-amz-request-id', requestId)

m_msg = "%s: %s\r\n" % (('x-amz-id-2', str(uuid.uuid1())))
self.transport.write(m_msg)

e_msg = ex.make_xml_string(self._path, str(uuid.uuid1()))
pycb.log(logging.INFO, "===== e_msg is %s"%e_msg)
#self.transport.write("\r\n")
self.transport.write(e_msg)
pycb.log(logging.INFO, "===== self.transport.write(e_msg)")


self.transport.loseConnection()
 
U

Ulrich Eckhardt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top