diff options
| author | Dmitry Stogov <dmitry@php.net> | 2004-01-27 15:49:34 +0000 | 
|---|---|---|
| committer | Dmitry Stogov <dmitry@php.net> | 2004-01-27 15:49:34 +0000 | 
| commit | a6c94a8bf96adbdf1adae579f754c32447edd444 (patch) | |
| tree | 6767ac18baf47a5cd7496dfa3f6604741d05a01e | |
| parent | 1b6f17628156f55b339f006dba48aae1ac364e97 (diff) | |
| download | php-git-a6c94a8bf96adbdf1adae579f754c32447edd444.tar.gz | |
SOAP Fault uses HTTP status code 500
| -rw-r--r-- | ext/soap/php_http.c | 47 | ||||
| -rw-r--r-- | ext/soap/soap.c | 14 | 
2 files changed, 35 insertions, 26 deletions
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 73c72e661b..1e7c61255d 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -215,12 +215,13 @@ int send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *location, char *so  int get_http_soap_response(zval *this_ptr, char **buffer, int *buffer_len TSRMLS_DC)  { -	char *http_headers, *http_body, *content_type, *http_version, http_status[4], *cookie_itt; +	char *http_headers, *http_body, *content_type, *http_version, *cookie_itt;  	int http_header_size, http_body_size, http_close;  	php_stream *stream;  	zval **trace, **tmp;  	char* connection;  	int http_1_1 = 0; +	int http_status = 0;  	if (zend_hash_find(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket"), (void **)&tmp) == SUCCESS) {  		php_stream_from_zval_no_verify(stream,tmp); @@ -247,8 +248,7 @@ int get_http_soap_response(zval *this_ptr, char **buffer, int *buffer_len TSRMLS  		if (tmp != NULL) {  			tmp++; -			strncpy(http_status,tmp,4); -			http_status[3] = '\0'; +			http_status = atoi(tmp);  		}  		/* @@ -257,22 +257,30 @@ int get_http_soap_response(zval *this_ptr, char **buffer, int *buffer_len TSRMLS  		Maybe try and test for some of the 300's 400's specfics but not  		right now. -		if (strcmp(http_status,"200")) -		{ -			zval *err; -			char *http_err; - -			MAKE_STD_ZVAL(err); -			ZVAL_STRING(err, http_body, 1); -			http_err = emalloc(strlen("HTTP request failed ()") + 4); -			sprintf(http_err, "HTTP request failed (%s)", http_status); -			add_soap_fault(thisObj, "Client", http_err, NULL, err TSRMLS_CC); -			efree(http_err); -			return; -		}*/ - -		/* Try and get headers again */ -		if (!strcmp(http_status, "100")) { +		if (http_status >= 200 && http_status < 300) { +		} else if (http_status >= 300 && http_status < 400) { +			add_soap_fault(this_ptr, "Client", "HTTTP redirection is not supported", NULL, NULL TSRMLS_CC); +		} else if (http_status == 400) { +			add_soap_fault(this_ptr, "Client", "Bad Request", NULL, NULL TSRMLS_CC); +		} else if (http_status == 401) { +			add_soap_fault(this_ptr, "Client", "Unauthorized Request", NULL, NULL TSRMLS_CC); +		} else if (http_status == 405) { +			add_soap_fault(this_ptr, "Client", "Method not allowed", NULL, NULL TSRMLS_CC); +		} else if (http_status == 415) { +			add_soap_fault(this_ptr, "Client", "Unsupported Media Type", NULL, NULL TSRMLS_CC); +		} else if (http_status >= 400 && http_status < 500) { +			add_soap_fault(this_ptr, "Client", "Client Error", NULL, NULL TSRMLS_CC); +		} else if (http_status == 500) { +			add_soap_fault(this_ptr, "Server", "Internal Server Error", NULL, NULL TSRMLS_CC); +		} else if (http_status >= 500 && http_status < 600) { +			add_soap_fault(this_ptr, "Server", "Server Error", NULL, NULL TSRMLS_CC); +		} else { +			add_soap_fault(this_ptr, "Client", "Unsupported HTTP status code", NULL, NULL TSRMLS_CC); +		} +		*/ + +		/* Try and get headers again +		if (http_status == 100") {  			efree(http_headers);  			if (!get_http_headers(stream, &http_headers, &http_header_size TSRMLS_CC)) {  				php_stream_close(stream); @@ -281,6 +289,7 @@ int get_http_soap_response(zval *this_ptr, char **buffer, int *buffer_len TSRMLS  				return FALSE;  			}  		} +		*/  		if (strncmp(http_version,"1.1", 3)) {  			http_1_1 = 1; diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 9a9c74e5ed..6ce113dd78 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1177,12 +1177,12 @@ PHP_METHOD(soapserver, handle)  		}  		sprintf(cont_len, "Content-Length: %d", size); +		sapi_add_header(cont_len, strlen(cont_len) + 1, 1);  		if (soap_version == SOAP_1_2) {  			sapi_add_header("Content-Type: application/soap+xml; charset=\"utf-8\"", sizeof("Content-Type: application/soap+xml; charset=\"utf-8\""), 1);  		} else {  			sapi_add_header("Content-Type: text/xml; charset=\"utf-8\"", sizeof("Content-Type: text/xml; charset=\"utf-8\""), 1);  		} -		sapi_add_header(cont_len, strlen(cont_len) + 1, 1);  		/* Free Memory */  		if (num_params > 0) { @@ -1253,11 +1253,16 @@ static void soap_error_handler(int error_num, const char *error_filename, const  		set_soap_fault(&ret, "Server", buffer, NULL, &outbuf TSRMLS_CC);  		doc_return = seralize_response_call(NULL, NULL, NULL, &ret, soap_version TSRMLS_CC); -		/* Build and send our headers + http 500 status */  		/*  		  xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8);  		*/  		xmlDocDumpMemory(doc_return, &buf, &size); + +		/* +		   Want to return HTTP 500 but apache wants to over write +		   our fault code with their own handling... Figure this out later +		*/ +		sapi_add_header("HTTP/1.1 500 Internal Service Error", sizeof("HTTP/1.1 500 Internal Service Error"), 1);  		sprintf(cont_len,"Content-Length: %d", size);  		sapi_add_header(cont_len, strlen(cont_len) + 1, 1);  		if (soap_version == SOAP_1_2) { @@ -1265,11 +1270,6 @@ static void soap_error_handler(int error_num, const char *error_filename, const  		} else {  			sapi_add_header("Content-Type: text/xml; charset=\"utf-8\"", sizeof("Content-Type: text/xml; charset=\"utf-8\""), 1);  		} -		/* -		   Want to return HTTP 500 but apache wants to over write -		   our fault code with their own handling... Figure this out later -		   sapi_add_header("HTTP/1.1 500 Internal Service Error", sizeof("HTTP/1.1 500 Internal Service Error"), 1); -		*/  		php_write(buf, size TSRMLS_CC);  		xmlFreeDoc(doc_return);  | 
