Philipp,
Sorry for being lazy, and thanks for the tips.  Here is my update version.
--- httptask.py.orig    Fri Jan 06 02:15:48 2006
+++ httptask.py Fri Sep 22 09:13:48 2006
@@ -126,6 +126,11 @@
             else:
                 close_it = 1
         elif version == '1.1':
+            #modified by Simon
+            if 'connection: close' in (header.lower() for header in
+                                        self.accumulated_headers):
+                #Close if 'connection: close' found in http response's header
+                close_it = 1
             if connection == 'close':
                 close_it = 1
             elif 'Transfer-Encoding' in response_headers:
@@ -134,8 +139,13 @@
             elif self.status == '304':
                 # Replying with headers only.
                 pass
+            #modified by simon
             elif not ('Content-Length' in response_headers):
-                close_it = 1
+                if 'content-length' not in (header[:14].lower() for header in
+                                            self.accumulated_headers):
+                    #Close if 'content-length' not found in
+                    #http response's header and self.response_headers
+                    close_it = 1
         else:
             # Close if unrecognized HTTP version.
             close_it = 1

 
On 9/21/06, Philipp von Weitershausen <[EMAIL PROTECTED]> wrote:
Hi Simon,

I have a few comments regarding style. First::

  if thisflag == False:
      ...

is unnecessarily long. Just write::

  if not thisflag:
      ...

Also, what is "thisflag"? It'd be better to give it a descriptive name.

> --- httptask.py.orig    Fri Jan 06 02:15:48 2006
> +++ httptask.py Thu Sep 21 17:31:17 2006
> @@ -126,6 +126,15 @@
>              else:
>                  close_it = 1
>          elif version == '1.1':
> +            #modified by Simon
> +            thisflag = False
> +            for each in self.accumulated_headers:
> +                if each.lower() == 'connection: keep-alive':
> +                    thisflag = True
> +                    break
> +            if thisflag == False:
> +                close_it = 1
> +

I think you make this a lot simpler::

  if 'connection: keep-alive' not in (header.lower() for header in
                                       self.accumulated_headers):
      close_it = 1

(instead of the lines you added)

>              if connection == 'close':
>                  close_it = 1
>              elif 'Transfer-Encoding' in response_headers:
> @@ -134,8 +143,15 @@
>              elif self.status == '304':
>                  # Replying with headers only.
>                  pass
> +            #modified by simon
>              elif not ('Content-Length' in response_headers):
> -                close_it = 1
> +                thisflag = False
> +                for each in self.accumulated_headers:
> +                    if each[:14].lower() == 'content-length':
> +                        thisflag = True
> +                        break
> +                if thisflag == False: #only content_length not exist in
> accumulated headers too
> +                    close_it = 1

I don't understand the comment (English grammar not correct), but my
suggestion would apply here as well, I think.

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to