failonstatus only works on backend provided status codes

2014-05-12 Thread Ruediger Pluem
While trying to use the failonstatus option of a balancer for the first time I 
noticed that it only works on status
codes provided by the backend not on status codes only set by the proxy (in my 
case a 502 because the backend timed
out). Is this intentional?


Regards

Rüdiger


Re: stop copying footers to r-headers_in?

2014-05-12 Thread Edward Lu
Both the things you caught were probably just errors I made in manually
merging the patch into 2.2.x; here's a revised version, just in case.
Thanks for the review.

I'm not really clear on the error-notes discussion. It makes sense that we
wouldn't care too much if we don't save the ones from reading the headers,
since we would have errored earlier if they were set. What happens
currently if there's an error reading the trailers and we are not merging
the trailers? Seems like the error-notes would just get overwritten with
nothing, in the general case, and they wouldn't be able to be used anywhere.


On Sun, May 11, 2014 at 3:55 PM, Yann Ylavic ylavic@gmail.com wrote:

 On Sun, May 11, 2014 at 6:35 PM, Yann Ylavic ylavic@gmail.com wrote:
  Restoring the status and notes (set before the body is read) seems
  unconditional to me.

 Well, actually I'm not really sure whether we should preserve or
 overwritte the error-notes here.

 In most cases (but PROXYREQ_RESPONSE discussed below), we are still
 reading the request.
 If an error is raised by ap_get_mime_headers(), we probably want to
 respond with a 4xx status and the corresponding error-notes (from this
 call).
 Moreover, the original error-notes (from the headers' parsing) is
 very likely to be unset here (or we would have responded with that
 error at that time).

 However, when ap_http_filter() is called in PROXYREQ_RESPONSE mode, we
 probably need to discard the forwarded response's trailers'
 error-notes, since the client is not the culprit.

 Maybe we should distinguish (at least) these 2 modes in the final patch.

Index: include/http_core.h
===
--- include/http_core.h	(revision 1593540)
+++ include/http_core.h	(working copy)
@@ -613,6 +613,10 @@
 #define AP_TRACE_ENABLE1
 #define AP_TRACE_EXTENDED  2
 int trace_enable;
+#define AP_MERGE_TRAILERS_UNSET0
+#define AP_MERGE_TRAILERS_ENABLE   1
+#define AP_MERGE_TRAILERS_DISABLE  2
+int merge_trailers;
 
 } core_server_config;
 
Index: include/httpd.h
===
--- include/httpd.h	(revision 1593540)
+++ include/httpd.h	(working copy)
@@ -1006,6 +1006,11 @@
  * record to improve 64bit alignment the next time we need to break
  * binary compatibility for some other reason.
  */
+
+/** MIME trailer environment from the request */
+apr_table_t *trailers_in;
+/** MIME trailer environment from the response */
+apr_table_t *trailers_out;
 };
 
 /**
Index: modules/http/http_filters.c
===
--- modules/http/http_filters.c	(revision 1593540)
+++ modules/http/http_filters.c	(working copy)
@@ -215,6 +215,7 @@
 ap_input_mode_t mode, apr_read_type_e block,
 apr_off_t readbytes)
 {
+core_server_config *conf;
 apr_bucket *e;
 http_ctx_t *ctx = f-ctx;
 apr_status_t rv;
@@ -222,6 +223,9 @@
 int http_error = HTTP_REQUEST_ENTITY_TOO_LARGE;
 apr_bucket_brigade *bb;
 
+conf = (core_server_config *)
+ap_get_module_config(f-r-server-module_config, core_module);
+
 /* just get out of the way of things we don't want. */
 if (mode != AP_MODE_READBYTES  mode != AP_MODE_GETLINE) {
 return ap_get_brigade(f-next, b, mode, block, readbytes);
@@ -403,13 +407,50 @@
 }
 
 if (!ctx-remaining) {
-/* Handle trailers by calling ap_get_mime_headers again! */
+int saved_status = f-r-status;
+apr_table_t *saved_headers_in = f-r-headers_in;
+const char *saved_error_notes = apr_table_get(f-r-notes,
+  error-notes);
+
+/* By default, don't merge in the trailers
+ * (treat UNSET as DISABLE) */
+if (conf-merge_trailers != AP_MERGE_TRAILERS_ENABLE) {
+f-r-status = HTTP_OK;
+f-r-headers_in = f-r-trailers_in;
+apr_table_clear(f-r-headers_in);
+}
+
 ctx-state = BODY_NONE;
 ap_get_mime_headers(f-r);
-e = apr_bucket_eos_create(f-c-bucket_alloc);
-APR_BRIGADE_INSERT_TAIL(b, e);
-ctx-eos_sent = 1;
-return APR_SUCCESS;
+if (f-r-status == HTTP_OK) {
+e = apr_bucket_eos_create(f-c-bucket_alloc);
+APR_BRIGADE_INSERT_TAIL(b, e);
+ctx-eos_sent = 1;
+rv = APR_SUCCESS;
+}
+else {
+const char *error_notes = apr_table_get(f-r-notes,
+error-notes);
+ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, f-r, 
+  Error while reading HTTP 

Re: failonstatus only works on backend provided status codes

2014-05-12 Thread Daniel Ruggeri
On 5/12/2014 7:31 AM, Ruediger Pluem wrote:
 While trying to use the failonstatus option of a balancer for the first time 
 I noticed that it only works on status
 codes provided by the backend not on status codes only set by the proxy (in 
 my case a 502 because the backend timed
 out). Is this intentional?

Hi, Ruediger;
   Yes, that was the original goal. The use case I was tackling was a
case where a backend application server started accepting HTTP requests
before the Servlets had all completed init(). In that case, the backend
returns a 503.

-- 
Daniel Ruggeri



Re: svn commit: r1594088 - in /httpd/httpd/branches/2.4.x/docs/manual/mod: mod_rewrite.html.en mod_rewrite.xml

2014-05-12 Thread Marion Christophe JAILLET

Hi,

in addition to my patch,

what is listed as specials in RewriteCond Server-Variables is not that 
special to mod_rewrite and are also available here: 
http://httpd.apache.org/docs/2.4/en/expr.html#vars.


So, IMHO, this specials category could be dropped and its items moved 
in the other lists.



Finally, r1132494 stated at the end:
Remaining tasks:
  Write docs.
So it is likely that other things need to be adjusted somewhere else in 
the doc. I've not checked neither what nor where.



Best regards,

CJ

Le 12/05/2014 22:50, jaillet...@apache.org a écrit :

Author: jailletc36
Date: Mon May 12 20:50:34 2014
New Revision: 1594088

URL: http://svn.apache.org/r1594088
Log:
Based on report from Ken Zalewski, on online doc.

Add missing Server-Variables useable in RewriteCond directive.
Introduced in r1132494
CONTEXT_PREFIX
CONTEXT_DOCUMENT_ROOT
Introduced in r737973
IPV6
Missing for ages!
SCRIPT_GROUP
SCRIPT_USER

I have added where I found it logical, feel free to adjust.
I have also reordered this table to ease reading.
Finally, I have beautified some tables at the end.

Modified:
 httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.html.en
 httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml