Differentiate between client and server requests
This commit is contained in:
parent
c4341b2861
commit
e7a1164e44
|
@ -131,7 +131,7 @@ enum socket_read_result send_request(struct http_message req, struct response_in
|
|||
if (start_time_result != 0) {
|
||||
return RESULT_PROCESSING_ERROR;
|
||||
}
|
||||
enum socket_read_result result = get_all_remote_parts(socket_fd, &res);
|
||||
enum socket_read_result result = get_all_remote_parts(socket_fd, TYPE_CLIENT, &res);
|
||||
struct timeval res_time;
|
||||
int end_time_result = gettimeofday(&res_time, NULL);
|
||||
if (end_time_result != 0) {
|
||||
|
|
|
@ -159,8 +159,7 @@ static char *read_body_until_eof(int socket_fd) {
|
|||
return result;
|
||||
}
|
||||
|
||||
//TODO: specify request vs response for eof differences
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, struct http_message *message) {
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, enum socket_type type, struct http_message *message) {
|
||||
ssize_t current_result_size = 0;
|
||||
char *result = NULL;
|
||||
char *buffer = malloc(BUFFER_SIZE * sizeof(char));
|
||||
|
@ -220,7 +219,11 @@ enum socket_read_result get_all_remote_parts(int socket_fd, struct http_message
|
|||
current_result_size += net_content_length + 1;
|
||||
result = realloc(result, current_result_size);
|
||||
body_result = read_body_by_content_length(socket_fd, net_content_length);
|
||||
} else if (read_info.strategy == STRATEGY_EOF && type == TYPE_SERVER) {
|
||||
// Servers cannot just wait for EOF with a client, so we just skip the action.
|
||||
body_result = "\0";
|
||||
} else {
|
||||
// In all other cases, such as if we have EOF strategy on a client.
|
||||
body_result = read_body_until_eof(socket_fd);
|
||||
current_result_size += strlen(body_result);
|
||||
result = realloc(result, current_result_size);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
enum line_type {RESULT_START_LINE, RESULT_HEADER, RESULT_BLANK_LINE, RESULT_NO_LINE};
|
||||
enum socket_read_result {RESULT_OK, RESULT_MALFORMED, RESULT_READ_ERROR, RESULT_PROCESSING_ERROR};
|
||||
enum socket_read_strategy {STRATEGY_CHUNKED, STRATEGY_CONTENT_LENGTH, STRATEGY_EOF};
|
||||
enum socket_type {TYPE_CLIENT, TYPE_SERVER};
|
||||
struct line_read_result {
|
||||
enum line_type line_type;
|
||||
// TODO: this just gets freed... do we need it?
|
||||
|
@ -22,6 +23,6 @@ struct socket_read_info {
|
|||
int length;
|
||||
};
|
||||
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, struct http_message *message);
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, enum socket_type type, struct http_message *message);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue