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

Discussion in 'Python' started by Levi Nie, Jan 15, 2013.

  1. Levi Nie

    Levi Nie Guest

    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()
    Levi Nie, Jan 15, 2013
    #1
    1. Advertising

  2. 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
    Ulrich Eckhardt, Jan 15, 2013
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bart Simpson
    Replies:
    1
    Views:
    399
    Werner Schiendl
    Oct 27, 2003
  2. Per
    Replies:
    4
    Views:
    299
    Stephen Prinster
    May 6, 2006
  3. Peter
    Replies:
    5
    Views:
    13,277
    Peter
    Jul 23, 2009
  4. 3legs

    File upload and quota problem

    3legs, Aug 23, 2004, in forum: ASP General
    Replies:
    1
    Views:
    83
    Steven Burn
    Aug 23, 2004
  5. George Hester

    Try over here likely more to the point here

    George Hester, Sep 30, 2004, in forum: Javascript
    Replies:
    0
    Views:
    98
    George Hester
    Sep 30, 2004
Loading...

Share This Page