atscppapi  1.0.9
C++ wrapper for Apache Traffic Server API
 All Classes Files Functions Enumerations Enumerator Macros
Public Types | Public Member Functions | Protected Member Functions | List of all members
atscppapi::TransformationPlugin Class Referenceabstract

The interface used when you wish to transform Request or Response body content. More...

#include "TransformationPlugin.h"

Inheritance diagram for atscppapi::TransformationPlugin:
atscppapi::TransactionPlugin atscppapi::Plugin atscppapi::transformations::GzipDeflateTransformation atscppapi::transformations::GzipInflateTransformation

Public Types

enum  Type { REQUEST_TRANSFORMATION = 0, RESPONSE_TRANSFORMATION }
 

Public Member Functions

virtual void consume (const std::string &data)=0
 
virtual void handleInputComplete ()=0
 
virtual ~TransformationPlugin ()
 
- Public Member Functions inherited from atscppapi::TransactionPlugin
void registerHook (Plugin::HookType hook_type)
 
- Public Member Functions inherited from atscppapi::Plugin
virtual void handleReadRequestHeadersPreRemap (Transaction &transaction)
 
virtual void handleReadRequestHeadersPostRemap (Transaction &transaction)
 
virtual void handleSendRequestHeaders (Transaction &transaction)
 
virtual void handleReadResponseHeaders (Transaction &transaction)
 
virtual void handleSendResponseHeaders (Transaction &transaction)
 
virtual void handleOsDns (Transaction &transaction)
 

Protected Member Functions

size_t produce (const std::string &)
 
size_t setOutputComplete ()
 
 TransformationPlugin (Transaction &transaction, Type type)
 
- Protected Member Functions inherited from atscppapi::TransactionPlugin
 TransactionPlugin (Transaction &transaction)
 
shared_ptr< MutexgetMutex ()
 

Detailed Description

The interface used when you wish to transform Request or Response body content.

Transformations are deceptively simple, transformations are chained so the output of one TransformationPlugin becomes the input of another TransformationPlugin. As data arrives it will fire a consume() and when all the data has been sent you will receive a handleInputComplete(). Data can be sent to the next TransformationPlugin in the chain by calling produce() and when the transformation has no data left to send it will fire a setOutputCompete().

Since a TransformationPlugin is a type of TransactionPlugin you can call registerHook() and establish any hook for a Transaction also; however, remember that you must implement the appropriate callback for any hooks you register.

A simple example of how to use the TransformationPlugin interface follows, this is an example of a Response transformation, the avialable options are REQUEST_TRANSFORMATION and RESPONSE_TRANSFORMATION which are defined in Type.

This example is a Null Transformation, meaning it will just spit out the content it receives without actually doing any work on it.

class NullTransformationPlugin : public TransformationPlugin {
public:
NullTransformationPlugin(Transaction &transaction)
}
void handleSendResponseHeaders(Transaction &transaction) {
transaction.getClientResponse().getHeaders().set("X-Content-Transformed", "1");
transaction.resume();
}
void consume(const string &data) {
produce(data);
}
}
};
See Also
Plugin
TransactionPlugin
Type
HookType

Member Enumeration Documentation

The available types of Transformations.

Enumerator
REQUEST_TRANSFORMATION 

Transform the Request body content

RESPONSE_TRANSFORMATION 

Transform the Response body content

Constructor & Destructor Documentation

TransformationPlugin::~TransformationPlugin ( )
virtual

Destructor for a TransformationPlugin

TransformationPlugin::TransformationPlugin ( Transaction transaction,
TransformationPlugin::Type  type 
)
protected

a TransformationPlugin must implement this interface, it cannot be constructed directly

Member Function Documentation

virtual void atscppapi::TransformationPlugin::consume ( const std::string &  data)
pure virtual

A method that you must implement when writing a TransformationPlugin, this method will be fired whenever an upstream TransformationPlugin has produced output.

Implemented in atscppapi::transformations::GzipInflateTransformation, and atscppapi::transformations::GzipDeflateTransformation.

virtual void atscppapi::TransformationPlugin::handleInputComplete ( )
pure virtual

A method that you must implement when writing a TransformationPlugin, this method will be fired whenever the upstream TransformationPlugin has completed writing data.

Implemented in atscppapi::transformations::GzipInflateTransformation, and atscppapi::transformations::GzipDeflateTransformation.

size_t TransformationPlugin::produce ( const std::string &  data)
protected

This method is how a TransformationPlugin will produce output for the downstream transformation plugin, if you need to produce binary data this can still be done with strings by a call to string::assign() or by constructing a string with string::string(char *, size_t).

size_t TransformationPlugin::setOutputComplete ( )
protected

This is the method that you must call when you're done producing output for the downstream TranformationPlugin.


The documentation for this class was generated from the following files: