You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Earl Hood <ea...@earlhood.com> on 2003/12/12 23:14:28 UTC

Remove HTTP_INTERNAL_SERVER_ERROR return from ApacheUtil___parse

libapreq version: 1.3

I am curious why ApacheUtil___parse returns HTTP_INTERNAL_SERVER_ERROR
if the content-type is unknown vs returning DECLINED?  Since HTTP
allows any content-type to be posted, returning DECLINED will allow
the caller to handle custom content-types.  And if the caller has
no need, the caller can choose to return HTTP_INTERNAL_SERVER_ERROR.

The reason I ask is I am working on a project where we may need to
support custom types of data posted, along with the common enctypes.

Semi-related to the above, it would be useful to make the util_read()
function public.  This way, the caller does not have "re-invent the
wheel" if they want to handle processing posted data themselves.

Following is a diff to the v1.3 source reflecting the desired changes
mentioned.  Please advise if these changes are inappropriate and/or
alternative solutions can be provided.


--- libapreq-1.3.old/c/apache_request.c	Thu Sep 25 14:31:10 2003
+++ libapreq-1.3/c/apache_request.c	Fri Dec 12 15:56:37 2003
@@ -68,7 +68,7 @@ static void req_plustospace(char *str)
     for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
 }
 
-static int util_read(ApacheRequest *req, const char **rbuf)
+int ApacheUtil_read(ApacheRequest *req, const char **rbuf)
 {
     request_rec *r = req->r;
     int rc = OK;
@@ -90,7 +90,7 @@ static int util_read(ApacheRequest *req,
 
 	*rbuf = ap_pcalloc(r->pool, length + 1);
 
-	ap_hard_timeout("[libapreq] util_read", r);
+	ap_hard_timeout("[libapreq] ApacheUtil_read", r);
 
 	while ((len_read =
 		ap_get_client_block(r, buff, sizeof(buff))) > 0) {
@@ -419,9 +419,9 @@ int ApacheRequest___parse(ApacheRequest 
 	   result = ApacheRequest_parse_multipart(req);
 	}
 	else {
-	    ap_log_rerror(REQ_ERROR,
-			  "[libapreq] unknown content-type: `%s'", ct);
-	    result = HTTP_INTERNAL_SERVER_ERROR;
+	    /* Return DECLINED to allow caller to handle custom
+	     * content-types */
+	    result = DECLINED;
 	}
     }
     else {
@@ -446,7 +446,7 @@ int ApacheRequest_parse_urlencoded(Apach
 	if (!strncaseEQ(type, DEFAULT_ENCTYPE, DEFAULT_ENCTYPE_LENGTH)) {
 	    return DECLINED;
 	}
-	if ((rc = util_read(req, &data)) != OK) {
+	if ((rc = ApacheUtil_read(req, &data)) != OK) {
 	    return rc;
 	}
 	if (data) {
diff -r -u -p libapreq-1.3.old/c/apache_request.h libapreq-1.3/c/apache_request.h
--- libapreq-1.3.old/c/apache_request.h	Thu Jul 10 06:08:50 2003
+++ libapreq-1.3/c/apache_request.h	Fri Dec 12 15:53:47 2003
@@ -98,6 +98,8 @@ char *ApacheRequest_params_as_string(Apa
 int ApacheRequest___parse(ApacheRequest *req);
 #define ApacheRequest_parse(req) \
     ((req)->status = (req)->parsed ? (req)->status : ApacheRequest___parse(req)) 
+int ApacheUtil_read(ApacheRequest *req, const char **rbuf);
+
 table *ApacheRequest_query_params(ApacheRequest *req, ap_pool *p);
 table *ApacheRequest_post_params(ApacheRequest *req, ap_pool *p);
 

-- 
Earl Hood, <ea...@earlhood.com>
Web: <http://www.earlhood.com/>
PGP Public Key: <http://www.earlhood.com/gpgpubkey.txt>