mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-15 00:34:05 +09:00
rework reinitialization of http_response
This commit is contained in:
@@ -51,10 +51,29 @@ http_response_add_data(http_response_t *response, const char *data, int datalen)
|
||||
response->data_length += datalen;
|
||||
}
|
||||
|
||||
|
||||
http_response_t *
|
||||
http_response_init(const char *protocol, int code, const char *message)
|
||||
http_response_create()
|
||||
{
|
||||
http_response_t *response;
|
||||
http_response_t *response = (http_response_t *) calloc(1, sizeof(http_response_t));
|
||||
if (!response) {
|
||||
return NULL;
|
||||
}
|
||||
/* Allocate response data */
|
||||
response->data_size = 1024;
|
||||
response->data = (char *) malloc(response->data_size);
|
||||
if (!response->data) {
|
||||
free(response);
|
||||
return NULL;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
void
|
||||
http_response_init(http_response_t *response, const char *protocol, int code, const char *message)
|
||||
{
|
||||
assert(response);
|
||||
response->data_length = 0; /* can be used to reinitialize a previously-initialized response */
|
||||
char codestr[4];
|
||||
|
||||
assert(code >= 100 && code < 1000);
|
||||
@@ -63,19 +82,6 @@ http_response_init(const char *protocol, int code, const char *message)
|
||||
memset(codestr, 0, sizeof(codestr));
|
||||
snprintf(codestr, sizeof(codestr), "%u", code);
|
||||
|
||||
response = calloc(1, sizeof(http_response_t));
|
||||
if (!response) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate response data */
|
||||
response->data_size = 1024;
|
||||
response->data = malloc(response->data_size);
|
||||
if (!response->data) {
|
||||
free(response);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add first line of response to the data array */
|
||||
http_response_add_data(response, protocol, strlen(protocol));
|
||||
http_response_add_data(response, " ", 1);
|
||||
@@ -83,8 +89,6 @@ http_response_init(const char *protocol, int code, const char *message)
|
||||
http_response_add_data(response, " ", 1);
|
||||
http_response_add_data(response, message, strlen(message));
|
||||
http_response_add_data(response, "\r\n", 2);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user