25
Why filters? Very flexible design Allows one module to modify the data that another module produces Finally, CGI's that output SSI tags A module that puts header and footer information on each page Many many more possibilities

Why filters?

Embed Size (px)

DESCRIPTION

Why filters?. Very flexible design Allows one module to modify the data that another module produces Finally, CGI's that output SSI tags A module that puts header and footer information on each page Many many more possibilities. Basic filters in 2.0. Core - PowerPoint PPT Presentation

Citation preview

Why filters?

Very flexible design

Allows one module to modify the data that another module produces Finally, CGI's that output SSI tags A module that puts header and footer

information on each page Many many more possibilities

Basic filters in 2.0

Core core_input_filter (read from network) core_output_filter (write to network) byterange_filter (send partial result) content_length_filter (compute C-L) sub-request_filter (remove extra EOS) OLD_WRITE (buffer for ap_r* funcs)

Basic filters in 2.0

HTTPD HTTP_IN (header/body determination) HTTP_HEADER (send headers) CHUNK (send data in chunks) DECHUNK (read chunked body from

client)

Modules SSI_filter (parse files for SSI tags)

Basic filters in 2.0

Modules SSI_filter (parse files for SSI tags) External (run external programs) Charset-encoding (translate between

charsets)

Possible Additional Filters

SSL (in process of being written, input and output)

Header/Footer (basic attempt in presentation and handouts)

Cache (cache data in output filter, send it later from cache_handler, basic attempt in CVS)

Handlers and filters

Handlers are the first filter in the chain Filters use functions like ap_fwrite Handlers use ap_rwrite

Handlers Generate data from nothing

Filters modify data passed to them from handlers, and other filters

Buckets and brigades

Bucket

File_bucket

socket_bucketshared_bucket

Bucket Flush

EOS

Brigade

BucketBucketBucketBucket

Types of buckets

Heap

Transient

Immortal

Pipe

Socket

File

Pool

MMAP

EOS

Flush

Error

Assumptions

All data can be broken into chunks Each chunk of data must come from the

same source

All HTTP data can be represented as strings of characters, even if not human readable

Filters must allow for optimal performance, even if they don't enforce it If files are in the output stream, then we

should use sendfile

Bucket Functions

apr_bucket_*_create Different arguments for each bucket type

apr_bucket_split

apr_bucket_destroy

apr_bucket_copy

apr_bucket_setaside

Bucket Creation

Bucket

File_bucket socket_bucket

Bucket

Flush

EOS

Bucket

Bucket

Bucket Split

Bucket

File

Bucket

bucket

Bucket

File_bucket

Bucket copy

socket_bucket

Bucket

socket_bucket

Bucket Bucket

Brigade Functions

apr_brigade_create

apr_brigade_split Splits based on buckets

apr_brigade_partition Splits based on offset

apr_brigade_destroy

apr_brigade_write, putstrs, vputstrs, putc, etc Write into a brigade with buffering

apr_brigade_write

Bucket brigade

file_bucket

apr_brigade_write("foo")

Bucket brigade

file_bucket "foo"

apr_brigade_write("bar")

Bucket brigade

file_bucket "foobar"

Input Filter flow

Input processor

Filter 2

Filter 1

HTTP_IN

Core input filter

Empty brigadeFull brigade

apcon_filter_in

Bucket- brigade

GET /foo bar.html HTTP/1.0ap_get_brigade(f- >next, b, mode);e = APR_BRIGADE_FIRST(b);

if (e- >type == NULL) { return NULL;}apr_bucket_read(e, &str, &length, 1);

if ((strncmp("GET ", str, strlen("GET "))) { return APR_SUCCESS;}

apcon_filter_in

Bucket- brigade

GET /foo bar.html HTTP/1.0

apr_bucket_split(e, strlen("GET ") + 1); e = APR_BUCKET_NEXT(e); apr_bucket_read(e, &str, &length, 1); /* this should work, because we are just searching for HTTP/1.0 or HTTP/1.1 */

begin = str + (strlen(str) - 3); do { begin- - ; } while (strncmp("HTTP", begin, 4) && (begin > str));

apcon_filter_in

Bucket- brigade

GET /foo bar.html HTTP/1.0

apr_bucket_split(e, begin - str - 1);

apr_bucket_read(e, &str, &length,1);

replace(" ", "%20");replace("\", "/");

generator/filter flow

Generate content

Filter 1

Filter 2

core_output_filter

Sub_request

Sr filter1

Sr filter 2

HTTP header filter

Header/Footer Filter

Bucket- brigade

File:/home/rbb/test.html

if (ctx- >state == 0) { ctx- >state = 1; if (conf- >headerf) { rr = ap_sub_request_uri(conf- >headerf, f- >r, f- >next); if (rr- >status == HTTP_OK) ap_run_sub_req(rr); } if (conf- >headert) { e = apr_bucket_immortal_create(conf- >headert, strlen(conf- >headert); APR_BRIGADE_INSERT_HEAD(e, bb); }}

Header/Footer Filter

Bucket- brigade

File:/home/rbb/test.html"This is a test"

ap_pass_brigade(f- >next, bb);return APR_SUCCESS;

More Information

Slides on-line Http://www.ntrnet.net/~rbb/presentations

Articles http://www.apachetoday.com http://www.covalent.net/

General Information http://www.apache.org [email protected]