Skip to content

Commit b184a1b

Browse files
authored
Merge pull request #5 from clibs/add-user-agent
Always define the User-Agent header
2 parents eebe4f6 + 024b6a8 commit b184a1b

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

clib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-get",
3-
"version": "0.2.2",
3+
"version": "0.3.0",
44
"repo": "clibs/http-get.c",
55
"description": "Simple HTTP GET requests backed by libcurl",
66
"keywords": [
@@ -14,4 +14,4 @@
1414
"src/http-get.c",
1515
"src/http-get.h"
1616
]
17-
}
17+
}

src/http-get.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ http_get_response_t *http_get_shared(const char *url, CURLSH *share) {
5555
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1);
5656
curl_easy_setopt(req, CURLOPT_WRITEFUNCTION, http_get_cb);
5757
curl_easy_setopt(req, CURLOPT_WRITEDATA, (void *) res);
58+
curl_easy_setopt(req, CURLOPT_USERAGENT, "http-get.c/"HTTP_GET_VERSION);
5859

5960
int c = curl_easy_perform(req);
6061

src/http-get.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <unistd.h>
1515
#endif
1616

17-
#define HTTP_GET_VERSION "0.1.0"
17+
#define HTTP_GET_VERSION "0.3.0"
1818

1919
typedef struct {
2020
char *data;

test/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ int main(int argc, char **argv) {
2323
assert(200 == res->status);
2424
http_get_free(res);
2525
});
26+
27+
it("should work when the User-Agent header is mandatory", {
28+
http_get_response_t *res = http_get("https://api.github.com/repos/clibs/clib/releases/latest");
29+
assert(res);
30+
assert(res->data);
31+
assert(res->ok);
32+
assert(200 == res->status);
33+
http_get_free(res);
34+
});
35+
2636
});
2737

2838
describe("http_get_file", {

0 commit comments

Comments
 (0)