Attachment 'squid-ecap-gzip_up_to_libecap-0.2.0.patch'

Download

   1 --- ./squid-ecap-gzip/src/adapter_gzip.cc.orig	2011-02-13 17:42:20.000000000 +0300
   2 +++ ./squid-ecap-gzip/src/adapter_gzip.cc	2012-10-31 13:24:24.513932121 +0400
   3 @@ -38,9 +38,9 @@
   4  #include <string.h>
   5  #include <stdlib.h>
   6  #include <iostream>
   7 -#include <libecap/common/message.h>
   8  #include <libecap/common/registry.h>
   9  #include <libecap/common/errors.h>
  10 +#include <libecap/common/message.h>
  11  #include <libecap/common/header.h>
  12  #include <libecap/common/names.h>
  13  #include <libecap/adapter/service.h>
  14 @@ -50,11 +50,9 @@
  15  
  16  namespace Adapter { // not required, but adds clarity
  17  	
  18 -	using libecap::size_type;
  19 -	using libecap::StatusLine;
  20 -	
  21 -	class Service: public libecap::adapter::Service {
  22 +using libecap::size_type;
  23  		
  24 +class Service: public libecap::adapter::Service {
  25  	public:
  26  		// About
  27  		virtual std::string uri() const; // unique across all vendors
  28 @@ -62,8 +60,8 @@
  29  		virtual void describe(std::ostream &os) const; // free-format info
  30  		
  31  		// Configuration
  32 -		virtual void configure(const Config &cfg);
  33 -		virtual void reconfigure(const Config &cfg);
  34 +		virtual void configure(const libecap::Options &cfg);
  35 +		virtual void reconfigure(const libecap::Options &cfg);
  36  		
  37  		// Lifecycle
  38  		virtual void start(); // expect makeXaction() calls
  39 @@ -75,14 +73,19 @@
  40  		
  41  		// Work
  42  		virtual libecap::adapter::Xaction *makeXaction(libecap::host::Xaction *hostx);
  43 -	};
  44  	
  45 +};
  46  	
  47 -	class Xaction: public libecap::adapter::Xaction {
  48 +
  49 +class Xaction: public libecap::adapter::Xaction {
  50  	public:
  51 -		Xaction(libecap::host::Xaction *x);
  52 +		Xaction(libecap::shared_ptr<Service> s, libecap::host::Xaction *x);
  53  		virtual ~Xaction();
  54  		
  55 +		// meta-information for the host transaction
  56 +		virtual const libecap::Area option(const libecap::Name &name) const;
  57 +		virtual void visitEachOption(libecap::NamedValueVisitor &visitor) const;
  58 +
  59  		// lifecycle
  60  		virtual void start();
  61  		virtual void stop();
  62 @@ -105,9 +108,11 @@
  63  		virtual bool callable() const;
  64  		
  65  	protected:
  66 +		void stopVb(); // stops receiving vb (if we are receiving it)
  67  		libecap::host::Xaction *lastHostCall(); // clears hostx
  68  		
  69  	private:
  70 +		libecap::shared_ptr<const Service> service; // configuration access
  71  		libecap::host::Xaction *hostx; // Host transaction rep
  72  		
  73  		typedef enum { opUndecided, opOn, opComplete, opNever } OperationState;
  74 @@ -137,7 +142,10 @@
  75  		} requirements;
  76  		
  77  		bool requirementsAreMet();
  78 -	};
  79 +};
  80 +
  81 +static const std::string CfgErrorPrefix =
  82 +	"Modifying Adapter: configuration error: ";
  83  	
  84  } // namespace Adapter
  85  
  86 @@ -169,7 +177,6 @@
  87  	return true;
  88  }
  89  
  90 -
  91  /**
  92   * Initializes the zlib data structures.
  93   */
  94 @@ -217,9 +224,7 @@
  95  	}
  96  }
  97  
  98 -/**
  99 - * Returns the URI of the VIGOS gzip eCAP service.
 100 - */
 101 +
 102  std::string Adapter::Service::uri() const {
 103  	return "ecap://www.vigos.com/ecap_gzip";
 104  }
 105 @@ -232,16 +237,16 @@
 106  	os << "HTTP GZIP compression eCAP adapter";
 107  }
 108  
 109 -void Adapter::Service::configure(const Config &) {
 110 +void Adapter::Service::configure(const libecap::Options &cfg) {
 111  	// this service is not configurable
 112  }
 113  
 114 -void Adapter::Service::reconfigure(const Config &) {
 115 +void Adapter::Service::reconfigure(const libecap::Options &cfg) {
 116  	// this service is not configurable
 117  }
 118  
 119  void Adapter::Service::start() {
 120 -	// libecap::adapter::Service::start();
 121 +	//libecap::adapter::Service::start();
 122  	// custom code would go here, but this service does not have one
 123  }
 124  
 125 @@ -260,12 +265,16 @@
 126  }
 127  
 128  libecap::adapter::Xaction *Adapter::Service::makeXaction(libecap::host::Xaction *hostx) {
 129 -	return new Adapter::Xaction(hostx);
 130 +	return new Adapter::Xaction(std::tr1::static_pointer_cast<Service>(self),
 131 +		hostx);
 132  }
 133  
 134  
 135 -Adapter::Xaction::Xaction(libecap::host::Xaction *x): hostx(x),
 136 -receivingVb(opUndecided), sendingAb(opUndecided) {
 137 +Adapter::Xaction::Xaction(libecap::shared_ptr<Service> aService,
 138 +	libecap::host::Xaction *x):
 139 +	service(aService),
 140 +	hostx(x),
 141 +	receivingVb(opUndecided), sendingAb(opUndecided) {
 142  }
 143  
 144  Adapter::Xaction::~Xaction() {
 145 @@ -275,17 +284,30 @@
 146  	}
 147  }
 148  
 149 +const libecap::Area Adapter::Xaction::option(const libecap::Name &) const {
 150 +	return libecap::Area(); // this transaction has no meta-information
 151 +}
 152 +
 153 +void Adapter::Xaction::visitEachOption(libecap::NamedValueVisitor &) const {
 154 +	// this transaction has no meta-information to pass to the visitor
 155 +}
 156 +
 157  void Adapter::Xaction::start() {
 158 +
 159  	gzipContext = 0;
 160  
 161  	Must(hostx);
 162 +
 163  	if (hostx->virgin().body()) {
 164  		receivingVb = opOn;
 165  		hostx->vbMake(); // ask host to supply virgin body
 166  	} else {
 167 +		// we are not interested in vb if there is not one
 168  		receivingVb = opNever;
 169  	}
 170  	
 171 +	/* adapt message header */
 172 +
 173  	libecap::shared_ptr<libecap::Message> adapted = hostx->virgin().clone();
 174      Must(adapted != 0);
 175  
 176 @@ -313,7 +335,6 @@
 177  		}
 178  	}
 179  	
 180 -	
 181  	/**
 182  	 * Checks if the response Cache-Control header allows transformation of the response.
 183  	 */
 184 @@ -334,7 +355,6 @@
 185  		}
 186  	}
 187  
 188 -
 189  	/**
 190  	 * Do not compress if response has a content-range header and status code "206 Partial content". 
 191  	 */
 192 @@ -369,7 +389,6 @@
 193  		}
 194  	}
 195  
 196 -
 197  	/**
 198  	 * Checks the Content-Encoding response header.
 199  	 * If this header is present, we must not compress the respone.
 200 @@ -384,16 +403,16 @@
 201  		this->requirements.responseContentTypeOk = false;
 202  	}
 203  
 204 -	
 205  	// delete ContentLength header because we may change the length
 206  	// unknown length may have performance implications for the host
 207  	adapted->header().removeAny(libecap::headerContentLength);
 208  
 209 -	// Add informational response header	
 210 +	// add a custom header
 211  	static const libecap::Name name("X-Ecap");
 212  	const libecap::Header::Value value = libecap::Area::FromTempString("VIGOS eCAP GZIP Adapter");
 213  	adapted->header().add(name, value);
 214  	
 215 +
 216  	// Add "Vary: Accept-Encoding" response header if Content-Type is "text/html"
 217  	if(requirements.responseContentTypeOk) {
 218  		static const libecap::Name varyName("Vary");
 219 @@ -442,8 +461,9 @@
 220  void Adapter::Xaction::abDiscard()
 221  {
 222  	Must(sendingAb == opUndecided); // have not started yet
 223 -	
 224  	sendingAb = opNever;
 225 +	// we do not need more vb if the host is not interested in ab
 226 +	stopVb();
 227  }
 228  
 229  void Adapter::Xaction::abMake()
 230 @@ -467,13 +487,12 @@
 231  void Adapter::Xaction::abStopMaking()
 232  {
 233  	sendingAb = opComplete;
 234 -	// we may still continue receiving
 235 +	// we do not need more vb if the host is not interested in more ab
 236 +	stopVb();
 237  }
 238  
 239  
 240 -libecap::Area Adapter::Xaction::abContent(size_type offset, size_type size)
 241 -{
 242 -	// required to not raise an exception on the final call with opComplete
 243 +libecap::Area Adapter::Xaction::abContent(size_type offset, size_type size) {
 244  	Must(sendingAb == opOn || sendingAb == opComplete);
 245  
 246  	// if complete, there is nothing more to return.
 247 @@ -487,17 +506,15 @@
 248  	return libecap::Area::FromTempBuffer((const char*)&gzipContext->gzipBuffer[offset], size);
 249  }
 250  
 251 -
 252 -void Adapter::Xaction::abContentShift(size_type size)
 253 -{
 254 -	Must(sendingAb == opOn);
 255 +void Adapter::Xaction::abContentShift(size_type size) {
 256 +	Must(sendingAb == opOn || sendingAb == opComplete);
 257  	gzipContext->sendingOffset += size;
 258  	hostx->vbContentShift(gzipContext->lastChunkSize);
 259  }
 260  
 261 -
 262  void Adapter::Xaction::noteVbContentDone(bool atEnd)
 263  {
 264 +
 265  	Must(gzipContext);
 266  	
 267  	gzipContext->zstream.total_out = 0;
 268 @@ -530,9 +547,9 @@
 269  	gzipContext->originalSize >>= 8;
 270  	gzipContext->gzipBuffer[gzipContext->compressedSize++] = (char) gzipContext->originalSize & 0xff;
 271  	
 272 +
 273  	Must(receivingVb == opOn);
 274  	receivingVb = opComplete;
 275 -	
 276  	if (sendingAb == opOn) {
 277  		hostx->noteAbContentDone(atEnd);
 278  		sendingAb = opComplete;
 279 @@ -546,8 +563,7 @@
 280  	Must(receivingVb == opOn);
 281  	Must(gzipContext);
 282  
 283 -	// get all virgin body
 284 -	const libecap::Area vb = hostx->vbContent(0, libecap::nsize);
 285 +        const libecap::Area vb = hostx->vbContent(0, libecap::nsize); // get all vb
 286  	
 287  	// calculate original byte size for GZIP footer
 288  	gzipContext->originalSize += vb.size;
 289 @@ -588,10 +604,8 @@
 290  	
 291  	gzipContext->compressedSize += gzipContext->zstream.total_out;
 292  	
 293 -	if(sendingAb == opOn)
 294 -	{
 295 +	if (sendingAb == opOn)
 296  		hostx->noteAbContentAvailable();
 297 -	}
 298  }
 299  
 300  
 301 @@ -599,6 +613,18 @@
 302      return hostx != 0; // no point to call us if we are done
 303  }
 304  
 305 +// tells the host that we are not interested in [more] vb
 306 +// if the host does not know that already
 307 +void Adapter::Xaction::stopVb() {
 308 +	if (receivingVb == opOn) {
 309 +		hostx->vbStopMaking();
 310 +		receivingVb = opComplete;
 311 +	} else {
 312 +		// we already got the entire body or refused it earlier
 313 +		Must(receivingVb != opUndecided);
 314 +	}
 315 +}
 316 +
 317  // this method is used to make the last call to hostx transaction
 318  // last call may delete adapter transaction if the host no longer needs it
 319  // TODO: replace with hostx-independent "done" method

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2016-06-08 18:00:06, 1.4 KB) [[attachment:gzip_ecap_extended_compressible_types.patch]]
  • [get | view] (2016-06-11 20:37:49, 1.6 KB) [[attachment:gzip_ecap_extended_compressible_types_latest.patch]]
  • [get | view] (2016-06-08 21:13:39, 1.4 KB) [[attachment:gzip_ecap_extended_compressible_types_v1.patch]]
  • [get | view] (2016-06-09 12:19:51, 1.6 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_2.patch]]
  • [get | view] (2016-06-11 20:31:49, 1.6 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_2.patch.latest]]
  • [get | view] (2016-06-12 14:51:20, 1.9 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_3.patch]]
  • [get | view] (2016-06-20 20:35:35, 1.2 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_4.patch]]
  • [get | view] (2016-06-20 20:50:23, 2.1 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_5.patch]]
  • [get | view] (2016-06-20 21:26:21, 1.8 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_6.patch]]
  • [get | view] (2016-06-18 16:44:11, 0.8 KB) [[attachment:gzip_ecap_vb_stop_on_done_v1.patch]]
  • [get | view] (2016-06-08 17:56:50, 1.4 KB) [[attachment:gzip_exap_extended_compressible_types.patch]]
  • [get | view] (2015-03-29 19:40:02, 1.5 KB) [[attachment:squid-ecap-gzip_all_text_compressed.patch]]
  • [get | view] (2015-03-29 19:35:49, 8.5 KB) [[attachment:squid-ecap-gzip_up_to_libecap-0.2.0.patch]]
  • [get | view] (2015-03-29 19:35:56, 9.2 KB) [[attachment:squid-ecap-gzip_up_to_libecap-1.0.0.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.