<commit_before>#include <stdio.h>
#include "requests.h"
#include "greatest.h"

#ifdef _DEBUG_
# define DEBUG(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
# define DEBUG(M, ...)
#endif

char *example = "https://gist.githubusercontent.com/mossberg/91093537c33e69e4da2c/raw/librequests_test.txt";
char *example_text = "Simple test file for librequests.";
char *posttestserver = "http://posttestserver.com/post.php";

void test_print(req_t *req)
{
    printf("Request URL: %s\n", req->url);
    printf("Response Code: %lu\n", req->code);
    printf("Response Size: %zu\n", req->size);
    printf("Response Body:\n%s\n", req->text);
}

TEST get()
{
    long code = 200;
    size_t size = 33;

    req_t req;
    CURL *curl = requests_init(&req);
    requests_get(curl, &req, example);

    ASSERT_EQ(code, req.code);
    ASSERT_EQ(size, req.size);
    ASSERT(strcmp(example_text, req.text) == 0);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT_EQ(1, req.ok);

    requests_close(&req);
    PASS();
}

TEST post()
{
    long code = 200;
    char *data[] = {
        "apple", "red",
        "banana", "yellow"
    };
    int data_size = sizeof(data)/sizeof(char*);

    req_t req;
    CURL *curl = requests_init(&req);
    char *body = requests_url_encode(curl, data, data_size);
    requests_post(curl, &req, posttestserver, body);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    curl_free(body);
    requests_close(&req);
    PASS();
}

TEST post_nodata()
{
    long code = 200;

    req_t req;
    CURL *curl = requests_init(&req);
    requests_post(curl, &req, posttestserver, NULL);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    requests_close(&req);
    PASS();
}

TEST post_headers()
{
    long code = 200;
    char *resp_hdrv[] = {
        "Content-Type: application/json",
        "Content-Hype: dude"
    };
    int headers_size = sizeof(resp_hdrv)/sizeof(char*);

    req_t req;
    CURL *curl = requests_init(&req);
    requests_post_headers(curl, &req, posttestserver, NULL, resp_hdrv,
                          headers_size);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    requests_close(&req);
    PASS();
}

TEST put()
{
    long code = 200;
    char *data[] = {
        "apple", "red",
        "banana", "yellow"
    };
    int data_size = sizeof(data)/sizeof(char*);

    req_t req;
    CURL *curl = requests_init(&req);
    char *body = requests_url_encode(curl, data, data_size);
    requests_put(curl, &req, posttestserver, body);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    curl_free(body);
    requests_close(&req);
    PASS();
}<commit_msg>Update tests to check for req_hdrv<commit_after>#include <stdio.h>
#include "requests.h"
#include "greatest.h"

#ifdef _DEBUG_
# define DEBUG(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
# define DEBUG(M, ...)
#endif

char *example = "https://gist.githubusercontent.com/mossberg/91093537c33e69e4da2c/raw/librequests_test.txt";
char *example_text = "Simple test file for librequests.";
char *posttestserver = "http://posttestserver.com/post.php";

void test_print(req_t *req)
{
    printf("Request URL: %s\n", req->url);
    printf("Response Code: %lu\n", req->code);
    printf("Response Size: %zu\n", req->size);
    printf("Response Body:\n%s\n", req->text);
}

TEST get()
{
    long code = 200;
    size_t size = 33;

    req_t req;
    CURL *curl = requests_init(&req);
    requests_get(curl, &req, example);

    ASSERT_EQ(code, req.code);
    ASSERT_EQ(size, req.size);
    ASSERT(strcmp(example_text, req.text) == 0);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT_EQ(1, req.ok);

    requests_close(&req);
    PASS();
}

TEST post()
{
    long code = 200;
    char *data[] = {
        "apple", "red",
        "banana", "yellow"
    };
    int data_size = sizeof(data)/sizeof(char*);

    req_t req;
    CURL *curl = requests_init(&req);
    char *body = requests_url_encode(curl, data, data_size);
    requests_post(curl, &req, posttestserver, body);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    curl_free(body);
    requests_close(&req);
    PASS();
}

TEST post_nodata()
{
    long code = 200;

    req_t req;
    CURL *curl = requests_init(&req);
    requests_post(curl, &req, posttestserver, NULL);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    requests_close(&req);
    PASS();
}

TEST post_headers()
{
    long code = 200;
    char *resp_hdrv[] = {
        "Content-Type: application/json",
        "Content-Hype: dude"
    };
    int headers_size = sizeof(resp_hdrv)/sizeof(char*);

    req_t req;
    CURL *curl = requests_init(&req);
    requests_post_headers(curl, &req, posttestserver, NULL, resp_hdrv,
                          headers_size);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strcmp(req.req_hdrv[0], "Content-Type: application/json") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);
    ASSERT_EQ(2, req.req_hdrc);

    requests_close(&req);
    PASS();
}

TEST put()
{
    long code = 200;
    char *data[] = {
        "apple", "red",
        "banana", "yellow"
    };
    int data_size = sizeof(data)/sizeof(char*);

    req_t req;
    CURL *curl = requests_init(&req);
    char *body = requests_url_encode(curl, data, data_size);
    requests_put(curl, &req, posttestserver, body);

    ASSERT_EQ(code, req.code);
    ASSERT(strcmp(req.resp_hdrv[0], "HTTP/1.1 200 OK\r\n") == 0);
    ASSERT(strstr(req.text, "Successfully") != NULL);
    ASSERT_EQ(1, req.ok);

    curl_free(body);
    requests_close(&req);
    PASS();
}
{'fraction_non_alphanumeric': 0.1756360832690825, 'fraction_numerical': 0.02266769468003084, 'mean_word_length': 3.2755438365194465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6831971', 'n_tokens_mistral': 2564, 'n_tokens_neox': 2410, 'n_words': 487}