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);
if (tmp != NULL) {
tmp++;
- strncpy(http_status,tmp,4);
- http_status[3] = '\0';
+ http_status = atoi(tmp);
}
/*
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);
return FALSE;
}
}
+ */
if (strncmp(http_version,"1.1", 3)) {
http_1_1 = 1;
}
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) {
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) {
} 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);