Welcome! Log In Create A New Profile

Advanced

[PATCH] Return http status code from XSLT

SamB
March 07, 2013 06:08PM
Hi,

this patch provides simple possibility to return http error code
from within XSLT transformation result.
This is simple way to quickly and correctly return i.e. 404 error
codes instead of producing dummy soft-404 pages.

Sample XSLT:
<xsl:template match="/">
<html xmlns:http="http://www.w3.org/http" status="400">
<xsl:copy-of select="."/>
</html>
</xsl:template>


Thanks
Sam


src/http/modules/ngx_http_xslt_filter_module.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/src/http/modules/ngx_http_xslt_filter_module.c
b/src/http/modules/ngx_http_xslt_filter_module.c
index a6ae1ce..c5710d5 100644
--- a/src/http/modules/ngx_http_xslt_filter_module.c
+++ b/src/http/modules/ngx_http_xslt_filter_module.c
@@ -27,6 +27,9 @@
#endif


+#define NGX_HTTP_XSLT_NS "http://www.w3.org/http"
+
+
typedef struct {
u_char *name;
void *data;
@@ -477,6 +480,7 @@ ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
ngx_uint_t i;
xmlChar *buf;
xmlDocPtr doc, res;
+ xmlNodePtr node;
ngx_http_xslt_sheet_t *sheet;
ngx_http_xslt_filter_loc_conf_t *conf;

@@ -551,6 +555,24 @@ ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
doc_type, type ? type : (u_char *) "(null)",
encoding ? encoding : (u_char *) "(null)");

+ node = xmlDocGetRootElement(doc);
+ if (node != NULL) {
+ xmlChar *attr = NULL;
+
+ attr = xmlGetNsProp(node, (const xmlChar *)"status", (const
xmlChar *)NGX_HTTP_XSLT_NS);
+ if (attr != NULL
+ && attr[0] != '\0') {
+
+ ngx_uint_t status = strtoul((const char *)attr, NULL, 10);
+
+ if (status > 0
+ && r->headers_out.status != status) {
+ r->headers_out.status = status;
+ r->headers_out.status_line.len = 0;
+ }
+ }
+ }
+
rc = xsltSaveResultToString(&buf, &len, doc, sheet[i - 1].stylesheet);

xmlFreeDoc(doc);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Return http status code from XSLT

SamB 1114 March 07, 2013 06:08PM

Re: [PATCH] Return http status code from XSLT

Maxim Dounin 571 March 11, 2013 02:22PM

Re: [PATCH] Return http status code from XSLT

SamB 892 April 25, 2013 04:00PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 191
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready