str_delete(req->headers, key_pos, next_pos - key_pos);
}
+const char *http_client_request_lookup_header(struct http_client_request *req,
+ const char *key)
+{
+ size_t key_pos, value_pos, next_pos;
+
+ if (!http_client_request_lookup_header_pos(req, key, &key_pos,
+ &value_pos, &next_pos))
+ return NULL;
+
+ /* don't return CRLF */
+ return t_strndup(str_data(req->headers) + value_pos,
+ next_pos - value_pos - 2);
+}
+
void http_client_request_set_date(struct http_client_request *req,
time_t date)
{
req = http_client_request(client, "GET", "host", "target",
test_http_client_request_callback, NULL);
+ test_assert(http_client_request_lookup_header(req, "qwe") == NULL);
+
/* add the first */
http_client_request_add_header(req, "qwe", "value1");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "value1");
test_assert_strcmp(str_c(req->headers), "qwe: value1\r\n");
/* replace the first with the same length */
http_client_request_add_header(req, "qwe", "234567");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "234567");
test_assert_strcmp(str_c(req->headers), "qwe: 234567\r\n");
/* replace the first with smaller length */
http_client_request_add_header(req, "qwe", "xyz");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "xyz");
test_assert_strcmp(str_c(req->headers), "qwe: xyz\r\n");
/* replace the first with longer length */
http_client_request_add_header(req, "qwe", "abcdefg");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "abcdefg");
test_assert_strcmp(str_c(req->headers), "qwe: abcdefg\r\n");
/* add the second */
http_client_request_add_header(req, "xyz", "1234");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "abcdefg");
+ test_assert_strcmp(http_client_request_lookup_header(req, "xyz"), "1234");
test_assert_strcmp(str_c(req->headers), "qwe: abcdefg\r\nxyz: 1234\r\n");
/* replace second */
http_client_request_add_header(req, "xyz", "yuiop");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "abcdefg");
+ test_assert_strcmp(http_client_request_lookup_header(req, "xyz"), "yuiop");
test_assert_strcmp(str_c(req->headers), "qwe: abcdefg\r\nxyz: yuiop\r\n");
/* replace the first again */
http_client_request_add_header(req, "qwe", "1234");
+ test_assert_strcmp(http_client_request_lookup_header(req, "qwe"), "1234");
+ test_assert_strcmp(http_client_request_lookup_header(req, "xyz"), "yuiop");
test_assert_strcmp(str_c(req->headers), "qwe: 1234\r\nxyz: yuiop\r\n");
/* remove the headers */
http_client_request_remove_header(req, "qwe");
+ test_assert(http_client_request_lookup_header(req, "qwe") == NULL);
+ test_assert_strcmp(http_client_request_lookup_header(req, "xyz"), "yuiop");
test_assert_strcmp(str_c(req->headers), "xyz: yuiop\r\n");
http_client_request_remove_header(req, "xyz");
+ test_assert(http_client_request_lookup_header(req, "qwe") == NULL);
+ test_assert(http_client_request_lookup_header(req, "xyz") == NULL);
test_assert_strcmp(str_c(req->headers), "");
http_client_request_abort(&req);