1
0
mirror of https://github.com/graygnuorg/pound.git synced 2026-10-28 11:35:07 +03:00
Commit Graph

164 Commits

Author SHA1 Message Date
Sergey Poznyakoff
8f0228551b Identify listeners and services by their names (labels) as well as indices
* src/config.c (parse_listen_http)
(parse_listen_https): Handle optional listener name.  Make sure it
is unique.
(parse_service): Make sure service name is unique.
* src/pound.h (LISTENER): New field: name.
* src/poundctl.tmpl: Show listener name, if available.
* svc.c (get_nth_listener, get_nth_service)
(get_nth_backend,ctl_getnum): Remove.
(IDENT): New data type.
(ctl_getident,locate_listener,locate_service)
(locate_backend): New functions.
(service_serialize): Represent NULL service name as null.
(listener_serialize): Add listener name.
(ctl_service,ctl_listener): Identify objects by their ids or numbers.

* NEWS: Document changes.
* doc/pound.8: Likewise.
* doc/poundctl.8: Likewise.
2023-03-03 12:14:33 +02:00
Sergey Poznyakoff
c7cad5c14e Allocate service name as necessary 2023-03-02 14:45:45 +02:00
Sergey Poznyakoff
a10dd4380a Fix memory leak in add_forwarded_headers 2023-02-28 09:39:40 +02:00
Sergey Poznyakoff
2c1256ec24 Enable buffering for plain HTTP backends
* src/http.c (open_backend): Always push buffered BIO
2023-02-20 22:43:36 +02:00
Sergey Poznyakoff
0f1589be51 Version 4.5.90 2023-02-20 09:15:24 +02:00
Sergey Poznyakoff
ac334995b2 Rewrite session handling
* src/config.c: Remove struct service_session.  The session parameters
are stored directly in the SERVICE object.
* src/http.c (http_request_get_path)
(http_header_list_locate_name, http_header_get_value): Now global.
(http_request_rebuild_query): Accept parameters with NULL value.
Free the query field before assigning it.
(match_cond): Return 0 if the parameter has NULL value.
* src/pound.h (SERVICE): Remove sess_start and sess_pat.  New field:
sess_id.
(get_backend): Change signature.
(upd_session): Change signature.
(http_request_get_path)
(http_header_list_locate_name, http_header_get_value): New protos.
* src/svc.c: Rewrite session handling functions using http request and
header functions.
2023-02-20 08:59:37 +02:00
Sergey Poznyakoff
6a87e134c5 Don't decode request parts. Return 500 on string expansion errors.
Mandatory percent decoding creates more problems than it solves. It
can perhaps be used optionally in request matching, but that is left
for further consideration.

* doc/pound.8: Document changes.
* src/http.c: Don't urldecode request parts.
(expand_string_to_buffer): Return -1 if invalid barckreferences or
accessors are encountered.
Don't bail out on percent-encodings.
(expand_string): Handle error return from expand_string_to_buffer.
* src/pound.h (http_request): Remove storage for decoded values.

* tests/poundharness.pl (getline): Handle undefined return gratiously.
(ParseRequest): Terminate thread on EOF.

* tests/backref.at: Update expected values.
* tests/experr.at: Likewise.
* tests/lstset.at: Likewise.
* tests/redirect.at: Likewise.
* tests/reqacc.at: Likewise.
* tests/set.at: Likewise.
2023-02-19 17:29:22 +02:00
Sergey Poznyakoff
0bb8e8ebbb Changes in poundharness
* tests/poundharness.pl: Run read_and_process in main thread.
Don't join threads on exit: all threads must be in detached state.
(read_and_process): Rewrite. Start one thread per each backend.
Within it, use the traditional endless loop (accept && do).
2023-02-18 20:46:22 +02:00
Sergey Poznyakoff
9b36acff63 Fix percent encoding/decoding of the path part.
Remove fragment handling: let's not meddle in the affairs of clients.

* NEWS: Reflect changes.
* doc/pound.8: Likewise.
* src/pound.h (http_request): Remove frag_raw and frag.
New field path_raw.
* src/http.c (expand_string_to_buffer): Don't allow subject
indexes after compatibility references (%N).
(urlencode): Take additional argument indicating whether the
string being encoded is a path.
(http_request_rebuild_url): Use path_raw.
(http_request_get_path): Decode path if necessary.
(http_request_free): Free path_raw.
* src/config.c: Remove fragment directives.
* tests/backref.at: Expect encoded URI.
* tests/experr.at: Likewise.
* tests/lstset.at: Remove fragment tests.
* tests/reqacc.at: Likewise.
* tests/set.at: Likewise.
2023-02-18 18:15:43 +02:00
Sergey Poznyakoff
e8c539a889 Improve tests
* src/http.c (expand_string_to_buffer): Improve error reporting.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
* tests/poundharness.pl (process_http_request): Add x-orig-
headers when returning 404.
* tests/backref.at: New file.
* tests/experr.at: New file.
* tests/header.at: New file.
* tests/lstset.at: New file.
* tests/not.at: Don't use obsolete/deprecated directives.
* tests/or.at: Likewise.
* tests/reqacc.at: Likewise.
* tests/virthost.at: Likewise.
2023-02-18 10:23:32 +02:00
Sergey Poznyakoff
3cd8178c85 Improve request matching and implement request modification directives.
Implement request accessors. Test rewrite rules.

Keep a cyclic queue of submatches

Up to 8 recent matches can be referenced in arguments to request
modification directives.  The notation $N refers to the Nth sub-
expression of the most recent match.  The notation $N(M) refers
to the Nth subexpression of the Mth recent match (match indexes
are 0-based).  For compatibility with versions 4.4-4.5, %N is
taken to mean $N(1).

* src/http.c: Rewrite http_request support.
(match_cond): Move from svc.c. Add support for new condition types.
(rewrite_apply): New function.
(send_to_backend): Call rewrite_apply.
(expand_string_to_buffer,expand_string): New function.
(expand_url): Rewrite using expand_string_to_buffer.
(urldecode,urlencode): New functions.
(submatch_reset,submatch_queue_init)
(submatch_queue_get,submatch_queue_push)
(submatch_queue_free): New functions.
(expand_string_to_buffer): Rewrite using submatch_queue.  All
uses changed.
Implement request accessors.
Fix dead loop occurring when invalid percent sequence is encountered.
(match_cond): Change signature. Use submatch_queue_push to
get new submatch slot each time it is needed.
(rewrite_rule_check, rewrite_op_apply): Change signature. All uses
changed.
(expand_string_to_buffer): Support ${N} notation
along with $N. Count accessor expansions in the return value.
(send_to_backend): Apply listener's rewrite rules.
(http_request_rebuild): Replace with three functions, invoked when
needed: http_request_rebuild_line, http_request_rebuild_url, and
http_request_rebuild_query.
(http_header_list_filter): Bugfix: revert condition.
* src/pound.c (pound_http_enqueue): Add explanatory comment.
(pound_http_destroy): Call submatch_queue_free.
* src/pound.h (query_param,QUERY_HEAD): New aggregate types.
(http_request): New fields: path, query_raw, query, frag_raw,
frag, orig_request_line, flags.
(be_redirect): Rename append_uri to has_uri, to avoid confusion.
(COND_PATH,COND_QUERY,COND_QUERY_PARAM,COND_FRAG): New cond types.
(query_param_match): New aggregate type.
(SERVICE_COND): New union member: qp.
(REWRITE_OP,REWRITE_OP_HEAD)
(REWRITE_RULE_HEAD,REWRITE_RULE): New aggregate types.
(SERVICE): New field: rewrite.
(struct submatch): Subject is allocated, so remove the const
qualifier.
(get_service): Simplify signature.
(match_cond): New proto.
(SMQ_SIZE): New constant.
(submatch_queue): New struct.
(submatch_free): Remove proto.
(submatch_queue_free): New proto.
(POUND_HTTP): Remove field sm.
New field smq.
(get_service): Change signature.
(LISTENER): Remove head_off and add_header. New field: rewrite.
(http_request): Replace "flags" field with "split".
HRF_* constants removed as well.
* src/svc.c (match_service,get_service): Change signature.
* src/config.c (input): Remove field: ready. New fields: putback
and putback_index.
(input_gettkn, input_putback): Rewrite putback handling.
New block statement: Rewrite ... [Else ...] End
New statements: Path, Query, QueryParam, Fragment,
SetHeader, DeleteHeader, SetURL, SetPath, SetQuery,
SetQueryParam, SetFragment.
Remove "AND" and "OR" block statements (these were undocumented
 shortcuts for "Match AND" and "Match OR").
(parse_header_remove): New function. Handles
HeaderRemove (HeadRemove) keywords.
HeaderAdd, and AddHeader are handled as synonims of SetHeader.
LISTENERs rewrite field.
Fix formation of regular expression for matchers.
Allow for "set" statements without enclosing Rewrite block.

* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
* tests/chgvis.at: New file.
* tests/reqacc.at: New file.
* tests/rwchain.at: New file.
* tests/set.at: New file.
* tests/headrem.at: Rewrite test to catch eventual bugs in
http_header_list_filter.

* NEWS: Document changes.
* doc/pound.8: Likewise.
2023-02-17 21:27:44 +02:00
Sergey Poznyakoff
3f5e1b543f Version 4.5 v4.5 2023-02-12 10:56:35 +02:00
Sergey Poznyakoff
c79893ae37 Implement metrics backend
This backend type implements openmetrics telemetry endpoint.
2023-02-10 19:23:36 +02:00
Sergey Poznyakoff
8a3d32cbb4 Update the poundctl.tmpl.5 manpage 2023-02-08 11:07:47 +02:00
Sergey Poznyakoff
f96e7bfa5a Arithmetic functions in templates
* NEWS: Update.
* src/tmpl.c: Implement arithmetic functions.
* doc/poundctl.tmpl.5: Document arithmetic functions.
* src/poundctl.tmpl: Convert times to milliseconds.
2023-02-07 13:07:58 +02:00
Sergey Poznyakoff
b86baf6ee4 Rename statistics fields 2023-02-05 15:34:24 +02:00
Sergey Poznyakoff
4a53008f99 Include stdandard deviation in the backend request statistics
* src/http.c (backend_update_stats): Maintain average squared time
per request.
* src/pound.h (BACKEND): New field: sqavg;
* src/poundctl.tmpl: Display number of requests and stddev.
* src/svc.c (backend_stats_serialize): New function: build
backend statistics object.
(backend_serialize): Call backend_stats_serialize.
2023-02-05 15:25:51 +02:00
Sergey Poznyakoff
d7e39e975c Always compile supervisor code 2023-02-05 13:02:13 +02:00
Sergey Poznyakoff
fc102714ed Revamp logging functions
* NEWS: Document changes.
* doc/pound.8: Likewise.
* src/config.c (config_parse): New options: -F, -e.
* src/pound.c (vlogmsg): Moved from svc.c.  In verbose mode, log
to syslog as well (if requested).
(logmsg): Moved from svc.c
(abend): New function.
(detach): New function.
(main): Use detach to daemonize.
Pass log_facility as third argument to openlog.
* src/pound.h (abend): New proto.
2023-02-05 12:10:09 +02:00
Sergey Poznyakoff
03ab51da09 Bugfixes
* src/config.c (parse_error_backend): Initialize local variable.
* src/http.c (bio_http_reply_start): Don't use Content-Type: with
HTTP 1.0
(http_err_reply): Mark connection as closed.
(error_response): Set response_code explicitly. Return 0 on success
(required by the caller).
2023-02-04 16:01:51 +02:00
Sergey Poznyakoff
ddc09264b1 Core statistics in the control output
* src/pound.c (workers_serialize): New function.
* src/pound.h (workers_serialize): New proto.
* src/poundctl.tmpl: Output core statistics.
* src/svc.c: Add core statistics.
* NEWS: Reflect changes.
2023-02-04 11:20:55 +02:00
Sergey Poznyakoff
fb651e676d Optionally maintain request timing statistics
* src/config.c (top_level_parsetab): New statement: BackendStats
* src/extern.h (enable_backend_stats): New extern.
* src/http.c (backend_update_stats): New function.
(do_http): Update stats.
* src/pound.c (enable_backend_stats): New global.
* src/poundctl.tmpl: Print average request processing time.
* src/svc.c (backend_serialize): If backend stats are enabled,
add avg_request_time.
2023-02-03 22:38:45 +02:00
Sergey Poznyakoff
14fe4ad549 Version 4.4.90 2023-02-03 17:33:10 +02:00
Sergey Poznyakoff
edfea27f25 New special backend: Error
* NEWS: Document changes.
* doc/pound.8: Likewise.
* src/config.c: New configuration directive: Error (Service section).
* src/http.c (error_response): New function.
(do_http): Handle the BE_ERROR backend type.
* src/pound.h (BE_ERROR): New backend type.
(struct be_error): New data type.
(BACKEND): Add be_error field.
(http_status_to_pound,pound_to_http_status): New protos.
* src/svc.c: Handle the BE_ERROR backend type.

* tests/error.at: New file.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
* tests/errfile.at: Pop the ERR501 define.
2023-02-03 17:31:00 +02:00
Sergey Poznyakoff
32e47ea593 Revamp the BACKEND structure as a union of specific backend types
* src/pound.h (be_regular, be_redirect)
(be_acme): New data types.
(BACKEND): Pack type-specific fields into a union.
* src/config.c: Reflect changes.
* src/http.c: Likewise.
* src/svc.c: Likewise.
2023-02-03 13:33:53 +02:00
Sergey Poznyakoff
3aeff79343 Support 303 and 308 redirection codes. 2023-02-03 08:09:48 +02:00
Sergey Poznyakoff
f22407699f Improve formatting of the error responses
* src/http.c (HTTP_STATUS): New field: reason.
(bio_err_reply): Format the default error page, unless non-NULL
content is given.
(err_reply): Remove. All uses updated.
* tests/errfile.at: Make custom page sufficiently distinct from
the default one.
2023-02-02 17:55:26 +02:00
Sergey Poznyakoff
1749b82701 Bugfixes.
* src/http.c (close_backend): New function.
(select_backend): Avoid fd leaks if same backend as the currently
active one is returned.
(do_http): Remove useless initializations.
2023-02-02 13:21:13 +02:00
Sergey Poznyakoff
8b718cd63f Replace LONG with a special type (typedef) for holding content length values
* src/config.c: Change handling of MaxRequest directive.
* src/extern.h (CHUNK_HEAD): Remove extern.
* src/http.c: Use CONTENT_LENGTH instead of LONG.
(get_content_length): New function.  Use it to get the value of a
content length from its string representation.
Use 0 instead of L0, and NO_CONTENT_LENGTH instead of L_1.
* src/pound.c: Remove CHUNK_HEAD.
* src/pound.h (CONTENT_LENGTH): New typedef.
(STRTOCLEN,PRICLEN): New defines.
(NO_CONTENT_LENGTH): New define.
(LONG,L0,L_1,STRTOL,ATOL,PRILONG): Remove.
(POUND_HTTP): Change type of the res_bytes fields.
(LISTENER): Change type of the max_req field.
* src/svc.c (vlogmsg): serialize access to stdout and stderr.
2023-02-01 17:43:21 +02:00
Sergey Poznyakoff
70fca7cde0 Bugfix
* src/pound.c (pound_http_dequeue): Keep track of the actual worker
count.
2023-02-01 16:45:07 +02:00
Sergey Poznyakoff
04b5184b8f Use response code to decide about ws_state, content availability etc.
* src/extern.h (RESP_SKIP, RESP_IGN): Remove.
* src/pound.c: Likewise.
* src/http.c (backend_response): Use response code alone, instead of
relying on regexps.
2023-01-31 22:21:58 +02:00
Sergey Poznyakoff
ef50b51748 Move backend selection and backend handling code to separate functions.
* src/http.c (redirect_response,acme_response)
(http_log,backend_response): Simplify arguments.
(bio_callback): Handle BIO_CB_FREE.
(set_callback): Change signature. Allocate the callback argument.
It will be freed by bio_callback.
(send_to_backend): New function.
(open_backend,select_backend): New functions.
(do_http): Use send_to_backend and select_backend.
* src/pound.h (POUND_HTTP): New fields: svc, backend, reneg_state.
(control_response): Change signature.
* src/svc.c (control_response): Simplify arguments.
2023-01-31 16:29:27 +02:00
Sergey Poznyakoff
b12a4cb91f Fix missing extern 2023-01-31 16:21:05 +02:00
Sergey Poznyakoff
cabeb051b7 Rename THR_ARG to POUND_HTTP.
Queue management functions renamed accordingly:

s/thr_arg_enqueue/pound_http_enqueue/g
s/thr_arg_dequeue/pound_http_dequeue/g
s/thr_arg_destroy/pound_http_destroy/g
2023-01-30 12:17:45 +02:00
Sergey Poznyakoff
2136f919ac Move backend to client interaction into a separate function.
* src/http.c (redirect_reply): Rename to redirect_response, change
signature.
(acme_reply): Rename to acme_response, change signature.
(http_log): Change signature. Take all information from THR_ARG and
backend.
(backend_response): New function.
(do_http): Move backend -> client part to backend_response, call
that function.
* src/pound.h (THR_ARG): New fields: ws_state, no_cont, conn_closed,
start_req, response_code, res_bytes.
* src/svc.c (control_reply): Rename to control_response. Change
signture.
2023-01-30 12:01:07 +02:00
Sergey Poznyakoff
775107ed86 Discontinue support for RPC over HTTP
* NEWS: Document changes.
* doc/pound.8: Document changes.
* src/config.c (listener_parse_xhttp): Allowed range for xHTTP is now
0..3
* src/http.c: Remove RPC over HTTP cruft.
* src/pound.h: Likewise.
* tests/xhttp.at: Remove related tests.
2023-01-26 17:53:50 +02:00
Sergey Poznyakoff
4c527cc783 Always use the same version in responses as the one in the request.
* src/http.c (bio_http_reply_start,bio_http_reply)
(bio_err_reply): New functions.
(err_reply): Take THR_ARG* as arg 1. All uses updated.
(redirect_reply): Use bio_http_reply to format response according
to the HTTP version in request.
(acme_reply): Use bio_http_reply_start for the same purpose.
(force_http_10): New finction.
(do_http): Remove force_10 local.
2023-01-26 17:30:35 +02:00
Sergey Poznyakoff
ecd8d14c0b Fix typo in README.md 2023-01-21 11:50:12 +02:00
Sergey Poznyakoff
bb6c550098 Revise the README.md 2023-01-20 11:41:51 +02:00
Sergey Poznyakoff
362601cfb1 Fix recent version number in NEWS 2023-01-19 23:03:00 +02:00
Sergey Poznyakoff
f679cc6f20 Version 4.4 v4.4 2023-01-19 22:48:38 +02:00
Sergey Poznyakoff
9e5c6d76e0 Revise the docs 2023-01-19 22:47:26 +02:00
Sergey Poznyakoff
292a691b56 Remove references to now not existing Apsis web page and address. 2023-01-19 17:33:07 +02:00
Sergey Poznyakoff
c3eb5df202 Fix expansion of %0 in Host matcher.
* src/http.c (expand_url): Fix subgroup range checking
* src/pound.h (COND_HOST): New SERVICE_COND type.
* src/config.c (parse_cond_host): Create COND_HOST node.
* src/svc.c (match_cond): For COND_HOST, adjust subject
and regmatch_t offset so they refer to the header value.
2023-01-19 15:30:11 +02:00
Sergey Poznyakoff
c0ddeafb73 Back-references to headers in Redirect and ACME statements
* NEWS: Document changes.
* doc/pound.8: Document changes.
* doc/poundctl.tmpl.5: Spell check
* src/config.c: Rewrite handling of URL, Header and Host directives.
* src/http.c (expand_url): Assume sm points to an array of two struct
submatch element. Treat $N as references to sm[SM_URL] and %N as
references to sm[SM_HDR].
* src/pound.c (thr_arg_destroy): Free both sm elements.
* src/pound.h (struct submatch): New field: subject.
(THR_ARG): Change type of sm.
* src/svc.c (submatch_reset): Reset subject to NULL.
(match_headers, match_cond): Rewrite submatch handling.
* tests/redirect.at: Add new tests.
* tests/url.at: Add new tests.
2023-01-19 14:27:19 +02:00
Sergey Poznyakoff
dc07891519 Add "all" keyword to HeaderOption 2023-01-18 13:22:35 +02:00
Sergey Poznyakoff
24a654bc28 Revise header modification directives.
* src/config.c (POUND_DEFAULTS): New field: header_options.
(parse_header_options): New function.
(listener_alloc): Initialize header_options.
(http_parsetab, https_parsetab, top_level_parsetab): New directive:
HeaderOption.
* src/http.c (http_header_list_locate_name): New function.
(http_header_list_append): Check if the header being added is already
in the list.  If so, act as instructed by the "replace" argument.
(http_header_list_append_list): Likewise.
(add_forwarded_headers): New function.
(do_http): Apply all header modifications after having selected the
service.  First, canned headers are added, then user-defined headers
added, then header removal directives are applied.
* src/pound.h (http_header_list_append): Change signature.  All uses
changed.

* tests/Makefile.am: Add new tests.
* tests/https.at: Remove unnecessary ClientCert directive.
* tests/optfwd.at: New test.
* tests/optorder.at: New test.
* tests/optssl.at: New test.
* tests/poundharness.pl: New variable expansions: LISTENER:PORT and
LISTENER:IP.  Same for BACKEND.
* tests/testsuite.at: Include new tests.

* NEWS: Document changes.
* doc/pound.8: Document changes.
* configure.ac: Version 4.3.90
2023-01-18 12:40:33 +02:00
Sergey Poznyakoff
e55d5ba66c Minor fixes 2023-01-17 14:54:29 +02:00
Sergey Poznyakoff
b5fe718081 Fix request parsing
* src/pound.h (http_request): New fields: method, version, url.
(cpURL): Remove.
* src/http.c (http_request_free): Free url.
(parse_http_request): Rewrite.
(do_http): Document int variables.
Remove url buffer.
* src/svc.c (cpURL): Remove.
2023-01-17 12:23:49 +02:00
Sergey Poznyakoff
eb9376895d Revert debugging changes 2023-01-17 00:24:10 +02:00