bool us_http_request_header_init_helper(us_http_request_header_t *self, const char *method, const char *host, const char *path, const char *content_type, int32_t content_length) { bool r = false; if (self) { us_delete(self->m_allocator, self->m_method); self->m_method = us_strdup(self->m_allocator, method); us_delete(self->m_allocator, self->m_path); self->m_path = us_strdup(self->m_allocator, path); us_delete(self->m_allocator, self->m_version); self->m_version = us_strdup(self->m_allocator, "HTTP/1.1"); if (self->m_path && self->m_method && self->m_version) { if (self->m_items->add(self->m_items, "Host", host)) { r = true; if (content_type) { r &= us_http_request_header_set_content_type(self, content_type); if (content_length != -1) { r &= us_http_request_header_set_content_length(self, content_length); } } } } } return r; }
us_http_header_item_t *us_http_header_item_list_add( us_http_header_item_list_t *self, const char *key, const char *value ) { us_http_header_item_t *item; item = us_new( self->m_allocator, us_http_header_item_t ); if ( item ) { item->m_key = 0; item->m_value = 0; item->m_key = us_strdup( self->m_allocator, key ); if ( item->m_key ) { item->m_value = us_strdup( self->m_allocator, value ); } if ( item->m_key == 0 || item->m_value == 0 ) { us_delete( self->m_allocator, item->m_key ); us_delete( self->m_allocator, item->m_value ); us_delete( self->m_allocator, item ); item = 0; } else { item->m_next = self->m_first; self->m_first = item; } } return item; }
us_http_response_header_t *us_http_response_header_create(us_allocator_t *allocator) { us_http_response_header_t *self; self = us_new(allocator, us_http_response_header_t); if (self) { self->m_allocator = allocator; self->destroy = us_http_response_header_destroy; self->m_code = 0; self->m_version = us_strdup(allocator, "HTTP/1.1"); self->m_items = us_http_header_item_list_create(allocator); if (!self->m_items) { self->destroy(self); self = 0; } } return self; }
bool us_http_response_header_set_version(us_http_response_header_t *self, const char *version) { us_delete(self->m_allocator, self->m_version); self->m_version = us_strdup(self->m_allocator, version); return self->m_version != 0; }
bool us_http_request_header_set_path(us_http_request_header_t *self, const char *path) { us_delete(self->m_allocator, self->m_path); self->m_path = us_strdup(self->m_allocator, path); return self->m_path != 0; }
bool us_http_request_header_set_method(us_http_request_header_t *self, const char *method) { us_delete(self->m_allocator, self->m_method); self->m_method = us_strdup(self->m_allocator, method); return self->m_method != 0; }