{"id":29079578,"url":"https://github.com/markusfisch/libhttp","last_synced_at":"2025-06-27T17:08:17.127Z","repository":{"id":10210643,"uuid":"12305891","full_name":"markusfisch/libhttp","owner":"markusfisch","description":"Light-weight C library for HTTP/1.1 requests","archived":false,"fork":false,"pushed_at":"2020-08-11T18:50:56.000Z","size":18,"stargazers_count":18,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-11T13:38:05.349Z","etag":null,"topics":["c","http-client"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markusfisch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-22T19:31:51.000Z","updated_at":"2022-11-28T23:50:20.000Z","dependencies_parsed_at":"2022-09-19T08:51:00.071Z","dependency_job_id":null,"html_url":"https://github.com/markusfisch/libhttp","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/markusfisch/libhttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2Flibhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2Flibhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2Flibhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2Flibhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markusfisch","download_url":"https://codeload.github.com/markusfisch/libhttp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusfisch%2Flibhttp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262298770,"owners_count":23289603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","http-client"],"created_at":"2025-06-27T17:06:33.760Z","updated_at":"2025-06-27T17:08:17.105Z","avatar_url":"https://github.com/markusfisch.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"libhttp\n=======\n\nLight-weight C library for [HTTP/1.1][1] requests.\nMeant for embedded environments or whereever [libcurl][3] would be just\ntoo much.\n\nFitness\n-------\n\nIf there's any chance you will ever need to make [HTTPS][2] requests or do\nanything else than just plain simple HTTP/1.1 requests, use [libcurl][3].\n\nThis library aims to remain as simple and portable as possible to offer\na nice and small alternative.\n\nSample\n------\n\n### Simple GET request\n\nFor a simple GET request you just need to call http_request() and\nhttp_response():\n\n\t#include \u003cstdio.h\u003e\n\t#include \u003cstdlib.h\u003e\n\t#include \u003cstring.h\u003e\n\t#include \u003cunistd.h\u003e\n\n\t#include \"http.h\"\n\n\tint main(int argc, char **argv) {\n\t\tint sd;\n\t\tstruct http_message msg;\n\n\t\tif (!--argc || (sd = http_request(*++argv)) \u003c 1) {\n\t\t\tperror(\"http_request\");\n\t\t\treturn -1;\n\t\t}\n\n\t\tmemset(\u0026msg, 0, sizeof(msg));\n\n\t\twhile (http_response(sd, \u0026msg) \u003e 0) {\n\t\t\tif (msg.content) {\n\t\t\t\twrite(1, msg.content, msg.length);\n\t\t\t}\n\t\t}\n\n\t\tclose(sd);\n\n\t\tif (msg.header.code != 200) {\n\t\t\tfprintf(\n\t\t\t\tstderr,\n\t\t\t\t\"error: returned HTTP code %d\\n\",\n\t\t\t\tmsg.header.code);\n\t\t}\n\n\t\treturn 0;\n\t}\n\n### Custom request\n\nIf you want to add/tweak some header values or do a POST request, use the low level functions http_parse_url(), http_connect() and http_send() to compose your request like this:\n\n\t#include \u003cstdio.h\u003e\n\t#include \u003cstdlib.h\u003e\n\t#include \u003cstring.h\u003e\n\t#include \u003cunistd.h\u003e\n\n\t#include \"http.h\"\n\n\tint post(int sd, struct http_url *url) {\n\t\tchar buf[1024];\n\n\t\tsnprintf(\n\t\t\tbuf,\n\t\t\tsizeof(buf),\n\t\t\t\"\\\n\tPOST /%s HTTP/1.1\\r\\n\\\n\tUser-Agent: Mozilla/4.0 (Linux)\\r\\n\\\n\tHost: %s\\r\\n\\\n\tAccept: */*\\r\\n\\\n\tContent-Length: 13\\r\\n\\\n\tConnection: close\\r\\n\\\n\t\\r\\n\\\n\tq=Test\u0026btn=Go\\r\\n\\\n\t\\r\\n\",\n\t\t\turl-\u003equery,\n\t\t\turl-\u003ehost);\n\n\t\tif (http_send(sd, buf)) {\n\t\t\tperror(\"http_send\");\n\t\t\treturn -1;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tint main(int argc, char **argv) {\n\t\tstruct http_url *url;\n\t\tstruct http_message msg;\n\t\tint sd;\n\n\t\tif (!(url = http_parse_url(*++argv)) ||\n\t\t\t\t!(sd = http_connect(url))) {\n\t\t\tfree(url);\n\t\t\tperror(\"http_connect\");\n\t\t\treturn -1;\n\t\t}\n\n\t\tmemset(\u0026msg, 0, sizeof(msg));\n\n\t\tif (!post(sd, url)) {\n\t\t\twhile (http_response(sd, \u0026msg) \u003e 0) {\n\t\t\t\tif (msg.content) {\n\t\t\t\t\twrite(1, msg.content, msg.length);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfree(url);\n\t\tclose(sd);\n\n\t\tif (msg.header.code != 200) {\n\t\t\tfprintf(\n\t\t\t\tstderr,\n\t\t\t\t\"error: returned HTTP code %d\\n\",\n\t\t\t\tmsg.header.code);\n\t\t}\n\n\t\treturn 0;\n\t}\n\nTesting\n-------\n\nThere's a bash script to test any URL list against libhttp:\n\n\t$ cd test \u0026\u0026 bash test.sh [FILE-WITH-URLS]\n\nIf you find bugs, please report them.\n\n[1]: https://en.wikipedia.org/wiki/HTTP\n[2]: https://en.wikipedia.org/wiki/HTTP_Secure\n[3]: https://github.com/bagder/curl\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusfisch%2Flibhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkusfisch%2Flibhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusfisch%2Flibhttp/lists"}