Implement get_read_info
This commit is contained in:
parent
8beb3f7c02
commit
96efb3c8aa
|
@ -85,6 +85,24 @@ static struct line_read_result read_line(const char *buffer, int buffer_size, st
|
|||
return result;
|
||||
}
|
||||
|
||||
static struct socket_read_info get_read_info(const struct http_header *headers) {
|
||||
const struct http_header *header_cursor = headers;
|
||||
struct socket_read_info info = {STRATEGY_EOF, -1};
|
||||
while (header_cursor != NULL) {
|
||||
header_cursor = header_cursor->next_header;
|
||||
if (headercmp(header_cursor, HEADER_TRANSFER_ENCODING) == 0 &&
|
||||
case_insensitive_strcmp(header_cursor->value, ENCODING_TYPE_CHUNKED)) {
|
||||
info.strategy = STRATEGY_CHUNKED;
|
||||
} else if (headercmp(header_cursor, HEADER_CONTENT_LENGTH) == 0
|
||||
&& info.strategy != STRATEGY_CHUNKED) {
|
||||
info.strategy = STRATEGY_CONTENT_LENGTH;
|
||||
info.length = atoi(header_cursor->value);
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, struct http_message *message) {
|
||||
ssize_t current_result_size = 0;
|
||||
char *result = NULL;
|
||||
|
|
|
@ -4,15 +4,23 @@
|
|||
#include "http_types.h"
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
#define HEADER_CONTENT_LENGTH "Content-Length"
|
||||
#define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
|
||||
#define ENCODING_TYPE_CHUNKED "chunked"
|
||||
|
||||
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};
|
||||
enum socket_read_strategy {STRATEGY_CHUNKED, STRATEGY_CONTENT_LENGTH, STRATEGY_EOF};
|
||||
struct line_read_result {
|
||||
enum line_type line_type;
|
||||
// TODO: this just gets freed... do we need it?
|
||||
char *line;
|
||||
int bytes_read;
|
||||
};
|
||||
struct socket_read_info {
|
||||
enum socket_read_strategy strategy;
|
||||
int length;
|
||||
};
|
||||
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, struct http_message *message);
|
||||
|
||||
|
|
Loading…
Reference in a new issue