Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E588B200BE4 for ; Wed, 21 Dec 2016 22:52:12 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E4256160B26; Wed, 21 Dec 2016 21:52:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 38F97160B18 for ; Wed, 21 Dec 2016 22:52:12 +0100 (CET) Received: (qmail 34685 invoked by uid 500); 21 Dec 2016 21:52:11 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 34669 invoked by uid 99); 21 Dec 2016 21:52:11 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2016 21:52:11 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 9B53118C4B4 for ; Wed, 21 Dec 2016 21:52:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.121 X-Spam-Level: X-Spam-Status: No, score=-0.121 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id ZPvd1jvhVQ_r for ; Wed, 21 Dec 2016 21:52:09 +0000 (UTC) Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id E51FE5F4EE for ; Wed, 21 Dec 2016 21:52:08 +0000 (UTC) Received: by mail-wm0-f54.google.com with SMTP id g23so34262577wme.1 for ; Wed, 21 Dec 2016 13:52:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=soF5oDmokC5DJ8wfOASnEXGzIcoi2YuXzC+z/pcwpGg=; b=a+C6SeABcU+EJ30dWzv0Emwwh9TFQ2JtBkvcC2VeyPBmI7nFFpyHA0HJW++1qP/l1a w1Ur+cLDLsyedFteB7tjYbgkLIn4gSLQFBkuPv3HH1fAptrkxU5G3Eu2zghMknq9di+q 9EOcMyeQkMrKQTCULD+gaJkMb695SGjyYV5HY9KHOHrFrxpW7cK7vkehCcEfyEJ/cnmI LGJ5REL0vgHjBMSxa2MtEF2yYxPwUAhAyzDedIyewvtn+z/bTFV2n9aeF14R4RJmFmM/ Zfh0aFxft2CKe9OXjmGresP6SE5vpciG1t4GBXPx+LD/YrNezpXkXRVY3/eTnLx73riE j2EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=soF5oDmokC5DJ8wfOASnEXGzIcoi2YuXzC+z/pcwpGg=; b=Qxto5vQ80nU0q8c3J7/UepwVf1aEAKK+ygdsp7XPKdV2DLl4Asp1J4hiTZ1EVcRIV+ DWsYkNTk7tMZ98QgeoNwnPR7+9cZvG+u8isBnU5JKqNpCQ3ErbF7QRHajfbreYN01XFv Ms07MHDF8meAOnzPfx3TxtgCTFVMnFmilBZj/NGpvGMUDyv+WT3stPzdrGK++bqXlmBp ok/95j7dA501Pgm1PGhJkSRYfdm+OZQyX1KE8JbH/7oq3Pkzmso40SWV3h1c9VjmraLj ENGiZdYsBYzhR3ROFfzTFs1Jq53fs4pdd9nDWOrVtGWqxuygHglI2+qqSMjO8IBY27ID gWaw== X-Gm-Message-State: AIkVDXI3lbJ7eXCq6a/rY2FmwWjHOQ5UHj0kBbUsU+eigWdL7BfensgmsFDVxv02M5z34w== X-Received: by 10.28.185.78 with SMTP id j75mr8602490wmf.14.1482357125696; Wed, 21 Dec 2016 13:52:05 -0800 (PST) Received: from ?IPv6:2a01:e35:8b73:8dd0:762f:68ff:fee5:8d8? ([2a01:e35:8b73:8dd0:762f:68ff:fee5:8d8]) by smtp.googlemail.com with ESMTPSA id r7sm32464211wjp.43.2016.12.21.13.52.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Dec 2016 13:52:05 -0800 (PST) Subject: Re: Change the content-length header for other filters To: modules-dev@httpd.apache.org References: From: Sorin Manolache Message-ID: <9b73c2a1-4fda-0d6d-37a2-6125521cec54@gmail.com> Date: Wed, 21 Dec 2016 22:52:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit archived-at: Wed, 21 Dec 2016 21:52:13 -0000 On 2016-12-21 22:10, André Rothe wrote: > Hi, > > I have a filter, which changes the content length of a POST request. > There are some key-value-pairs of the request, which the filter removes > before other filters process the request. > > But after my filter completes the request processing, I'll get: > > Sending error response: The request contained fewer content data than > specified by the content-length header > > I have tried to change the header key "Content-Length" and set the > new value like: > > apr_table_set(f->r->headers_in, "Content-Length", > apr_psprintf(f->r->pool, "%ld", len)); > > but it has no effect outside of my filter. The incoming request has a > content length of 1107 bytes. I modify the bucket brigade and it > contains at the end of my filter code only 1074 bytes (which is also > stored into "len"). > > What can I do to send the new content length along the filter chain? > > Thank you > André Hello, Could you please give us more details about how the body of the post request is read? Is it read in a third-party handler? Is is read by a standard apache module such as mod_proxy? If it's a third-party handler, do you happen to have the code? Why I'm asking: because it may happen that the reader (i.e. the code that triggers the chain of input filters) reads first the Content-Length header and then attempts to read N bytes, where N is the value of the Content-Length filter. In this case, it is no use to set Content-Length in your filter because anyway the reader has read the value of the Content-Length header before your filter had the opportunity to change it. A well-behaved reader should read until it finds an EOS bucket in the retrieved brigade. It should not rely on Content-Length. A trivial example why it should not use Content-Length is request body compression. A reader would get the brigade filtered by the INFLATE filter of mod_deflate, which contains many more bytes than indicated by Content-Length as this header contains the size of the compressed body. Best regards, Sorin