Using the cache with deflated responses

Hi,

I'm having trouble getting the cache to work with documents that are
compressed. That is, when the cache stores a document whose Content-Encoding
is `deflate', the compressed document is stored in the cache. However, when
the document is subsequently retrieved from the cache it is not decompressed.
I'll append the calls I'm using to initialize the library. 

Has anyone tried using the cache in conjunction with compressed responses?
Does anyone know what I'm doing wrong?

Thanks in advance,
James

Library init code:

    // Initialize tcp and buffered_tcp transports
    HTTransportInit();

    // Set up http and cache protocols. Do this instead of
    // HTProtocolPreemtiveInit(). 
    HTProtocol_add("http", "buffered_tcp", HTTP_PORT, YES, HTLoadHTTP, NULL);
    HTProtocol_add("cache", "local", 0, YES, HTLoadCache, NULL);

    // Initialize various before and after filters. See HTInit.c.
    HTNetInit();

    // Add basic authentication.
    HTAAInit();

    // Add proxy handling here. In HTProfile_newPreem...()
    // HTProxy_getEnvVars() is called. 02/09/98 jhrg
    
    // Register the default set of converters.
    _conv = HTList_new();
    HTConverterInit(_conv);
    HTFormat_setConversion(_conv);

    // Register the default set of transfer encoders and decoders
    HTList *transfer_encodings = HTList_new();
    HTTransferEncoderInit(transfer_encodings);
    HTFormat_setTransferCoding(transfer_encodings);

    // Register the default set of content encoders and decoders
    if (accept_deflate) {
#ifdef HT_ZLIB
	HTList *content_encodings = HTList_new();
	HTCoding_add(content_encodings, "deflate", NULL, HTZLib_inflate, 1.0);
	HTFormat_setContentCoding(content_encodings);
#endif /* HT_ZLIB */
    }

    // Register MIME headers for HTTP 1.1
    HTMIMEInit();

#ifdef GUI
    // Add progress notification, etc.
    HTAlert_add(dods_progress, HT_A_PROGRESS);
    HTAlert_add(dods_error_print, HT_A_MESSAGE);
    HTAlert_add(dods_username_password, HT_A_USER_PW);
    HTAlert_setInteractive(YES);
#endif
    if(!USE_CACHE) {
	// Disable the cache. 
	HTCacheTerminate();
	_cache_enabled = false;
    }
    else {
	// Instead, set up the cache.
	// Remove any stale lock file.  This may not be safe if multiple
	// people are using the same cache directory at once.
	tempstr = new char[strlen(cache_root)+7];
	strcpy(tempstr, cache_root);
	strcpy(tempstr+strlen(cache_root), "/.lock");
	tempstr[strlen(cache_root)+6] = (char)0;
	remove(tempstr);
	_cache_root = new char[strlen(cache_root)+1];
	strcpy(_cache_root, cache_root);
	if(HTCacheInit(cache_root, MAX_CACHE_SIZE) == YES) {
	    HTCacheMode_setMaxCacheEntrySize(MAX_CACHED_OBJ);
	    if(IGNORE_EXPIRES) HTCacheMode_setExpires(HT_EXPIRES_IGNORE);
	    else HTCacheMode_setExpires(HT_EXPIRES_AUTO);
	    _cache_enabled = true;
	}
	else {
	    // Disable the cache. 
	    HTCacheTerminate();
	    _cache_enabled = false;
	}
    }
    
    if (www_verbose_errors)
	HTError_setShow(HT_ERR_SHOW_INFO);
    else
	HTError_setShow(HT_ERR_SHOW_FATAL);
	
    // Add our own filter to update the history list.
    HTNet_addAfter(http_terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    // We add our own parsers for content-description and server so that
    // we can test for these fields and operate on the resulting document
    // without using the stream stack mechanism (which seems to be very
    // complicated). jhrg 11/20/96
    HTHeader_addParser("content-description", NO, description_handler);
    // Added DODS server header because `Server:' is used by Java. We check
    // first for `XDODS-Server:' and use that if found. Then look for
    // `Server:' and finally default to 0.0. 12/16/98 jhrg
    HTHeader_addParser("xdods-server", NO, server_handler);
    HTHeader_addParser("server", NO, server_handler);

    // Add xdods_accept_types header. 2/17/99 jhrg
    HTHeader_addGenerator(xdods_accept_types_header_gen);
    // Add Cache-Control header. Use this to suppres caching of compressed
    // data reqeusts which, for some reason, are broken. 12/1/99 jhrg
    HTHeader_addGenerator(cache_control_header_gen);

Received on Wednesday, 15 March 2000 15:04:47 UTC