<commit_before>#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <3ds.h>

#include "task.h"
#include "../../list.h"
#include "../../error.h"
#include "../../../core/linkedlist.h"
#include "../../../core/screen.h"
#include "../../../json/json.h"
#include "../../../stb_image/stb_image.h"

static Result task_populate_titledb_download(u32* downloadSize, void* buffer, u32 maxSize, const char* url) {
    Result res = 0;

    if(downloadSize != NULL) {
        *downloadSize = 0;
    }

    httpcContext context;
    if(R_SUCCEEDED(res = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1))) {
        char userAgent[128];
        snprintf(userAgent, sizeof(userAgent), "Mozilla/5.0 (Nintendo 3DS; Mobile; rv:10.0) Gecko/20100101 FBI/%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);

        u32 responseCode = 0;
        if(R_SUCCEEDED(res = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify))
           && R_SUCCEEDED(res = httpcAddRequestHeaderField(&context, "User-Agent", userAgent))
           && R_SUCCEEDED(res = httpcBeginRequest(&context))
           && R_SUCCEEDED(res = httpcGetResponseStatusCode(&context, &responseCode))) {
            if(responseCode == 200) {
                u32 size = 0;
                u32 bytesRead = 0;
                while(size < maxSize && (res = httpcDownloadData(&context, &((u8*) buffer)[size], maxSize - size < 0x1000 ? maxSize - size : 0x1000, &bytesRead)) == HTTPC_RESULTCODE_DOWNLOADPENDING) {
                    size += bytesRead;
                }<commit_msg>Add Keep-Alive header to TitleDB requests.<commit_after>#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <3ds.h>

#include "task.h"
#include "../../list.h"
#include "../../error.h"
#include "../../../core/linkedlist.h"
#include "../../../core/screen.h"
#include "../../../json/json.h"
#include "../../../stb_image/stb_image.h"

static Result task_populate_titledb_download(u32* downloadSize, void* buffer, u32 maxSize, const char* url) {
    Result res = 0;

    if(downloadSize != NULL) {
        *downloadSize = 0;
    }

    httpcContext context;
    if(R_SUCCEEDED(res = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1))) {
        char userAgent[128];
        snprintf(userAgent, sizeof(userAgent), "Mozilla/5.0 (Nintendo 3DS; Mobile; rv:10.0) Gecko/20100101 FBI/%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);

        u32 responseCode = 0;
        if(R_SUCCEEDED(res = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify))
           && R_SUCCEEDED(res = httpcAddRequestHeaderField(&context, "User-Agent", userAgent))
           && R_SUCCEEDED(res = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive"))
           && R_SUCCEEDED(res = httpcBeginRequest(&context))
           && R_SUCCEEDED(res = httpcGetResponseStatusCode(&context, &responseCode))) {
            if(responseCode == 200) {
                u32 size = 0;
                u32 bytesRead = 0;
                while(size < maxSize && (res = httpcDownloadData(&context, &((u8*) buffer)[size], maxSize - size < 0x1000 ? maxSize - size : 0x1000, &bytesRead)) == HTTPC_RESULTCODE_DOWNLOADPENDING) {
                    size += bytesRead;
                }
{'fraction_non_alphanumeric': 0.16176925456232602, 'fraction_numerical': 0.029693782864212804, 'mean_word_length': 2.887019230769231, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7572153', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1107, 'n_words': 213}