From patchwork Wed Oct 7 13:46:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luigi Tarenga X-Patchwork-Id: 527300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DBDE3140D89 for ; Thu, 8 Oct 2015 00:46:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=CrV8tZRL; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id EB9F6284731; Wed, 7 Oct 2015 15:44:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 14EA72805DB for ; Wed, 7 Oct 2015 15:44:26 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-lb0-f170.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com [209.85.217.170]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 7 Oct 2015 15:44:25 +0200 (CEST) Received: by lbbwt4 with SMTP id wt4so11735197lbb.1 for ; Wed, 07 Oct 2015 06:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=5WCULzSGcs9gU4UBAdbNnm5HYgHkhf2SE5A4gbGcoaY=; b=CrV8tZRL+nG95M4+4jW8If3QoV7CODsufxcEBfMhkOzK5PNmr6G4AH1Zav5hD4IVzc orPDp+XMkZzciHpO2b90qRu1rSrNS+z1rCxDXqVHT0T2AdEh/CAPBhTGuj6ChWyJ11bW NcGJqAJa4S5M+fOWmtbWkW5GlTrYaJALJF07cYiUNGb7tqp6xEytBYMHWvHEpEWfdZfy EEG66IfgmNetDgv8T6xFg3BLNUVr+B8QDHiidSCqAtpw4SqpIZpyJ3oRX0G+tRh3Jshr X9MbkeEwhKamV/UNv4/ta0N5654jc6l+z5tyfr5jiguAEPx/xJRi1nL8GLWO/p1RG3iR cxvg== X-Received: by 10.112.167.8 with SMTP id zk8mr631243lbb.15.1444225551899; Wed, 07 Oct 2015 06:45:51 -0700 (PDT) Received: from [172.24.49.5] ([193.138.231.101]) by smtp.googlemail.com with ESMTPSA id d82sm6364958lfg.22.2015.10.07.06.45.50 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Oct 2015 06:45:51 -0700 (PDT) Message-ID: <56152229.7010009@gmail.com> Date: Wed, 07 Oct 2015 15:46:17 +0200 From: Luigi Tarenga User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] uhttpd: chunked output from cgi script X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Hello list, I'm working on a CGI written in lua and I'm using uhttpd as webserver on a tp-link AP. I'm using external CGI interpreter, not embedded lua. I need that the output from my CGI is chunked since I would like to avoid to buffer the whole response and calculate the "Content-Length". I discovered that uhttpd try to send chunked response if the response is a normal 200 OK and the method is a GET. This is my case but unfortunately I ended with a strange behavior where sometimes the GET return with chunked content and sometimes not. I have an html page that call the CGI with a jquery method: the board.lua script return a piece of html code (without headers and footers). The output of the CGI is always the same between test. Debugging the http traffic with firefox I see that the GET of board.lua take about 33ms when the output is chunked and 20s (the full keep-alive timeout) when the output is not chunked. I see the response headers and it contain Transfer-Encoding: "chunked" directive in one case on not in the other. From client side everything seems correctly following what the websever gives back. If I directly call cgi-bin/board.lua it seems to always return in 33ms. Debugging the code I came up with the idea that where there are multiple GET on one http session if one GET is solved with a 204 or 304 that all other GET can't be chunked anymore. In fact my html page load other pages (css, js, etc about 5 GET in one page refresh). I tried with a simple patch (I'm sure this is not the best solution though) that seems to correct my problem. I would like to know if this have sense, if it has been corrected in other uhttpd version or if my patch broke with some RFC recommendation. my openwrt version is: DISTRIB_ID='OpenWrt' DISTRIB_RELEASE='Chaos Calmer' DISTRIB_REVISION='r46910' DISTRIB_CODENAME='chaos_calmer' DISTRIB_TARGET='ar71xx/generic' DISTRIB_DESCRIPTION='OpenWrt Chaos Calmer 15.05' DISTRIB_TAINTS='no-all no-ipv6' thank you in advance Luigi --- file.c 2015-10-07 15:39:45.169056639 +0200 +++ file.c 2015-10-07 15:39:55.859056443 +0200 @@ -807,9 +807,10 @@ return true; d = dispatch_find(url, pi); - if (d) + if (d) { + cl->request.respond_chunked = true; uh_invoke_handler(cl, d, url, pi); - else + } else uh_file_request(cl, url, pi, tb); return true;