roxen.lists.roxen.general

Subject Author Date
RE: [PATCH 14/17] New module: gzip-on-the-fly Arjan van Staalduijnen <Arjan[dot]van[dot]Staalduijnen[at]rtl[dot]nl> 21-01-2009
> You alluded to outgoing content-encoding and transfer-encoding
headers,
> where do I check for them and does the vary callback work for them as
well?

My module starts the filter like this (since it was still in early
stages of development only it has some hardcoded values which you made
configurable already. This code was never used in production yet.):


void|mapping filter(mapping|void result, RequestID id)
{
        if (id->misc->internal_get
                || !(result && result->error && result->error == 200)
//              || has_prefix(result->type || "", "image/")
                || !has_prefix(result->type || "", "text/")
                || has_prefix(id->raw_url, "/edit/")
                || !stringp(result->data)
                || id->misc->gzip_filter++
                || sizeof(result->data) < 10000)
                return 0;

#if ROXEN_MAJOR_VERSION > 4
        id->register_vary_callback("accept-encoding",
accept_encoding_callback);
#else
        id->register_vary_callback("Accept-Encoding",
accept_encoding_callback);
#endif

        if (!has_index(id->request_headers, "accept-encoding")
//              || !has_value(id->request_headers["accept-encoding"],
"gzip")
                || !has_value(id->request_headers["accept-encoding"],
"deflate")        )
                return 0;

        if (result->headers)
        {
                hmglog(HMG_LOG, "HEADERS %O", result->headers);
                foreach (indices(result->headers), string h)
                {
                        string lc = lower_case(h);
                        if ( (< "transfer-encoding", "content-encoding"
>)[ lc ] )
                        {       // transfer-encoding or content-encoding
already set, do nothing!
                                // this also disables handling of
'Transfer-Encoding: chunked', which is a good thing
                                return 0;
                        }
                }
        }

// no content-encoding or transfer-encoding was set on the result,
// so now it's soon enough to register those callbacks,
// because the result CAN vary depending on thise headers.
#if ROXEN_MAJOR_VERSION > 4
        id->register_vary_callback("transfer-encoding",
transfer_encoding_callback);
        id->register_vary_callback("content-encoding",
content_encoding_callback);
#else
        id->register_vary_callback("Transfer-Encoding",
transfer_encoding_callback);
        id->register_vary_callback("Content-Encoding",
content_encoding_callback);
#endif

// compression done from here
// Be sure to verify if the compressed result actually returned less
data than it's input?
....
	return result;
}

string accept_encoding_callback( string u, RequestID id )
{
        if (has_value((id->request_headers["accept-encoding"] || ""),
"x-gzip"))
                return "x-gzip";
        else if (has_value((id->request_headers["accept-encoding"] ||
""), "gzip"))
                return "gzip";
        else
                return "";      // no gzip support
}


string transfer_encoding_callback( string u, RequestID id )
{
        return (string)has_index(id->request_headers,
"transfer-encoding");
}


string content_encoding_callback( string u, RequestID id )
{
        return (string)has_index(id->request_headers,
"content-encoding");
}



Regards,

Arjan

__________________________________________________________
Deze e-mail en de inhoud is vertrouwelijk en uitsluitend bestemd voor de
geadresseerde(n). Indien u niet de geadresseerde bent van deze e-mail verzoeken
wij u dit direct door te geven aan de verzender door middel van een reply e-mail
en de ontvangen e-mail uit uw systemen te verwijderen. Als u geen geadresseerde
bent, is het niet toegestaan om kennis te nemen van de inhoud, deze te kopieren,
te verspreiden, bekend te maken aan derden noch anderszins te gebruiken.

The information contained in this e-mail is confidential and may be legally
privileged. It is intended solely for the addressee. If you are not the intended
recipient, any disclosure, copying, distribution or any action taken or omitted
to be taken in reliance on it, is prohibited and may be unlawful. Please notify
us immediately if you have received it in error by reply e-mail and then delete
this message from your system.
__________________________________________________________