--- fopen-wrappers.c.orig Thu May 4 16:48:50 2000 +++ fopen-wrappers.c Thu May 4 16:49:00 2000 @@ -443,6 +443,12 @@ int reqok = 0; int i, len; + int http_heads=0; + zval **arr,**tmp2; + HashTable *hash_arr; + char *string_key; + ulong num_key; + FILE *fp = NULL; struct sockaddr_in server; unsigned short portno; @@ -509,7 +515,20 @@ } strlcat(hdr_line, " HTTP/1.0\r\n", sizeof(hdr_line)); SOCK_WRITE(hdr_line, *socketd); + + if(zend_hash_find(EG(active_symbol_table),"http_heads",sizeof("http_heads"),(void**)&arr)==SUCCESS) + { + hash_arr=HASH_OF(*arr); + http_heads=1; + } + if(http_heads && zend_hash_find(hash_arr,"Authorization",sizeof("Authorization"),(void **) &tmp2)==SUCCESS) + { + convert_to_string_ex(tmp2); + snprintf(hdr_line,sizeof(hdr_line),"Authorization: %s\r\n",(*tmp2)->value.str.val); + SOCK_WRITE(hdr_line,*socketd); + } + else /* send authorization header if we have user/pass */ if (resource->user != NULL && resource->pass != NULL) { scratch = (char *) emalloc(strlen(resource->user) + strlen(resource->pass) + 2); @@ -530,6 +549,13 @@ efree(scratch); efree(tmp); } + if(http_heads && zend_hash_find(hash_arr,"From",sizeof("From"),(void **) &tmp2)==SUCCESS) + { + convert_to_string_ex(tmp2); + snprintf(hdr_line,sizeof(hdr_line),"From: %s\r\n",(*tmp2)->value.str.val); + SOCK_WRITE(hdr_line,*socketd); + } + else /* if the user has configured who they are, send a From: line */ if (cfg_get_string("from", &scratch) == SUCCESS) { if (snprintf(hdr_line, sizeof(hdr_line), @@ -538,6 +564,14 @@ } } + if(http_heads && zend_hash_find(hash_arr,"Host",sizeof("Host"),(void **) &tmp2)==SUCCESS) + { + convert_to_string_ex(tmp2); + snprintf(hdr_line,sizeof(hdr_line),"Host: %s\r\n",(*tmp2)->value.str.val); + SOCK_WRITE(hdr_line,*socketd); + } + else + { /* send a Host: header so name-based virtual hosts work */ if (resource->port != 80) { len = snprintf(hdr_line, sizeof(hdr_line), @@ -549,11 +583,45 @@ if (len > 0) { SOCK_WRITE(hdr_line, *socketd); } + } /* identify ourselves and end the headers */ - SOCK_WRITE("User-Agent: PHP/" PHP_VERSION "\r\n\r\n", *socketd); - - body = 0; + if(http_heads && zend_hash_find(hash_arr,"User-Agent",sizeof("User-Agent"),(void **) &tmp2)==SUCCESS) + { + convert_to_string_ex(tmp2); + snprintf(hdr_line,sizeof(hdr_line),"User-Agent: %s\r\n",(*tmp2)->value.str.val); + SOCK_WRITE(hdr_line,*socketd); + } + else + { + SOCK_WRITE("User-Agent: PHP/" PHP_VERSION "\r\n", *socketd); + } + + /* additional heads */ + zend_hash_internal_pointer_reset(hash_arr); + while(zend_hash_get_current_data(hash_arr,(void **) &tmp2)==SUCCESS) + { + convert_to_string_ex(tmp2); + if(zend_hash_get_current_key(hash_arr,&string_key,&num_key)==HASH_KEY_IS_LONG) + { + snprintf(hdr_line,sizeof(hdr_line),"%ld: %s\r\n",num_key,(*tmp2)->value.str.val); + SOCK_WRITE(hdr_line,*socketd); + } + else + { + if(strcmp(string_key,"User-Agent")!=0 && strcmp(string_key,"Host")!=0 && + strcmp(string_key,"From")!=0 && strcmp(string_key,"Authorization")!=0) + { + snprintf(hdr_line,sizeof(hdr_line),"%s: %s\r\n",string_key,(*tmp2)->value.str.val); + SOCK_WRITE(hdr_line,*socketd); + } + efree(string_key); + } + zend_hash_move_forward(hash_arr); + } + SOCK_WRITE("\r\n",*socketd); + + body = 0; location[0] = '\0'; if (!SOCK_FEOF(*socketd)) { /* get response header */ @@ -586,6 +654,7 @@ } } } + if (!reqok) { SOCK_FCLOSE(*socketd); *socketd = 0;