Skip to content
This repository
Browse code

Merge pull request #20 from athomason/master

Suppress 400 if client disconnected (mk 2)
  • Loading branch information...
commit 505bb8621a76e00ca53f284bf15b62c9238d5afb 2 parents 24c5eb8 + f9fbf8b
Tatsuhiko Miyagawa authored September 18, 2011

Showing 1 changed file with 15 additions and 11 deletions. Show diff stats Hide diff stats

  1. 26  lib/Twiggy/Server.pm
26  lib/Twiggy/Server.pm
@@ -160,7 +160,8 @@ sub _accept_handler {
160 160
 
161 161
             1;
162 162
         }) {
163  
-            $self->_bad_request($sock);
  163
+            my $disconnected = ($@ =~ /^client disconnected/);
  164
+            $self->_bad_request($sock, $disconnected);
164 165
         }
165 166
     };
166 167
 }
@@ -217,24 +218,27 @@ sub _create_req_parsing_watcher {
217 218
         } catch {
218 219
             undef $headers_io_watcher;
219 220
             undef $timeout_timer;
220  
-            $self->_bad_request($sock);
  221
+            my $disconnected = /^client disconnected/;
  222
+            $self->_bad_request($sock, $disconnected);
221 223
         }
222 224
     };
223 225
 }
224 226
 
225 227
 sub _bad_request {
226  
-    my ( $self, $sock ) = @_;
  228
+    my ( $self, $sock, $disconnected ) = @_;
227 229
 
228 230
     return unless defined $sock and defined fileno $sock;
229 231
 
230  
-    $self->_write_psgi_response(
231  
-        $sock,
232  
-        [
233  
-            400,
234  
-            [ 'Content-Type' => 'text/plain' ],
235  
-            [ ],
236  
-        ],
237  
-    );
  232
+    my $response = [
  233
+        400,
  234
+        [ 'Content-Type' => 'text/plain' ],
  235
+        [ ],
  236
+    ];
  237
+
  238
+    # if client is already gone, don't try to write to it
  239
+    $response = [] if $disconnected;
  240
+
  241
+    $self->_write_psgi_response($sock, $response);
238 242
 
239 243
     return;
240 244
 }

0 notes on commit 505bb86

Please sign in to comment.
Something went wrong with that request. Please try again.