File: readme.txt

package info (click to toggle)
trafficserver 9.2.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 53,008 kB
  • sloc: cpp: 345,484; ansic: 31,134; python: 24,200; sh: 7,271; makefile: 3,045; perl: 2,261; java: 277; pascal: 119; sql: 94; xml: 2
file content (88 lines) | stat: -rw-r--r-- 2,800 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
About append_transform.c

This example is based on null_transform.c. It appends text to the body
of an HTML text response document on its way from the cache to the
client.

The plugin first makes sure that it has received a "200 OK"
response from the origin server.  It then verifies that the returned
document is of type "text/html".  It "transforms" the document by
appending text to the file.   To read and write to the body of the
document, the plugin uses functions similar to those in null_transform.c.

You place the text to be appended in a file, and you must provide the
path to the file in plugin.config. In other words, plugin.config must
have a line similar to the following:

  append_transform.so path/to/file

Specify an absolute path to the text file, or a relative path as
described in the file-plugin README.

TSPluginInit does the following:

- makes sure that there is a text file specified in plugin.config
	(if not, it returns an error message)

- calls the function load to load the contents of the file into
	a buffer to be appended to HTML response bodies

- sets up the global hook to call back the plugin:
	TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK,
TSContCreate (transform_plugin, NULL));

The load function does the following (similar to file-1.c):

- opens the file specified in plugin.config using
	TSfopen

- creates a buffer for the text to be appended using
	TSIOBufferCreate

- creates a buffer reader for the text to be appended using
	TSIOBufferReaderAlloc

- reads the contents of the file in to the buffer using:
	TSIOBufferStart
	TSIOBufferBlockWriteStart
	TSfread
	TSIOBufferProduce
	TSIOBufferReaderAvail

- closes the file using
	TSfclose

The transform_plugin function does the following:

- tests the response body to make sure it is text/html, using
	the function "transformable". The transformable function
	uses the following API calls:
	TSHttpTxnServerRespGet
	TSHttpHdrStatusGet
	TSMimeHdrFieldFind
	TSMimeHdrFieldValueStringGet

- if the response body is deemed transformable, transform_plugin calls
	transform_add

- continues the HTTP transaction using
	TSHttpTxnReenable

The transform_add function does the following:

- creates a continuation for the append transform, using
	TSTransformCreate (append_transform, txnp);
	The handler function for this continuation is
	append_transform.

- adds a transaction hook for the append transform, using
	TSHttpTxnHookAdd(txnp, TS_HTTP_RESPONSE_TRANSFORM_HOOK, connp);
	This transaction hook sets up a callback during transactions.
	When the event TS_HTTP_RESPONSE_TRANSFORM_HOOK happens,
	the append_transform function is called back.

The remaining functions in the plugin, append_transform and
handle_transform, are similar to null_transform and
handle_transform in the null_transform.c plugin.