-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.c
865 lines (642 loc) · 21.3 KB
/
http.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
#include "http.h"
#include "base64.h"
#include "asprintf.h"
#include "logging.h"
#include <stdio.h>
#include <openssl/hmac.h>
const char* s_user_agent = "test";
#define ohttp_conn_io_has(CONN, HANDLE) ((CONN)->io && (CONN)->io->HANDLE)
#define x_easy_setopt(opt, val) \
if ((curl_status = curl_easy_setopt( \
conn->curl, opt, val)) != CURLE_OK) { \
return OSS_CURLE(curl_status); \
}
static
void pointer_clear(void **pptr)
{
free(*pptr);
*pptr = NULL;
}
static
void ohttp_header_to_kv(const char *buffer, size_t buflen, char **key, char **value)
{
*key = NULL;
*value = NULL;
/* TODO: MING: implement it */
*key = strdup("key");
*value = strdup("value");
}
static
size_t ohttp_curl_header_function(void* ptr, size_t size, size_t nmemb, void *ctx)
{
struct ohttp_connection *conn = (struct ohttp_connection *) ctx;
char* buffer = ptr;
size_t buflen = size * nmemb;
struct ohttp_response *response = &conn->response;
char* key;
char* value;
ohttp_header_to_kv(buffer, buflen, &key, &value);
oss_kvlist_append_nodup(&response->headers, key, value);
return buflen;
}
static
size_t ohttp_response_error_append(struct ohttp_response *response, char *ptr, size_t len)
{
if (oss_buffer_append(&response->ebody, ptr, len)) {
return len;
} else {
ologe("ohttp_response_error_append failed\n");
return 0;
}
}
static
size_t ohttp_curl_read_function(char *ptr, size_t size, size_t nmemb, void *ctx)
{
size_t len = size * nmemb;
struct ohttp_connection *conn = (struct ohttp_connection *) ctx;
if (ohttp_conn_io_has(conn, on_send_body)) {
oss_i64 n = conn->io->on_send_body(ptr, len, conn->io);
if (n < 0)
return CURL_READFUNC_ABORT;
else
return (size_t)n;
}
return CURL_READFUNC_ABORT;
}
static
void set_response_status(struct ohttp_connection *conn)
{
struct ohttp_response *response = &conn->response;
if (response->status == OSSE_UNKNOWN) {
CURLcode curl_status;
long http_status;
if ((curl_status = curl_easy_getinfo(conn->curl, CURLINFO_RESPONSE_CODE, &http_status)) != CURLE_OK) {
response->status = OSS_CURLE(curl_status);
} else {
response->status = http_status;
}
ologd("info status is %d\n", response->status);
}
}
static
size_t ohttp_curl_write_function(char *ptr, size_t size, size_t nmemb, void *ctx)
{
size_t len = size * nmemb;
struct ohttp_connection *conn = (struct ohttp_connection *) ctx;
struct ohttp_response *response = &conn->response;
set_response_status(conn);
if (response->status < 0) {
ologe("error status is %d\n", response->status);
return 0;
}
if (response->status >= 400) {
return ohttp_response_error_append(response, ptr, len);
}
if (response->status >= 200 && response->status < 300) {
if (ohttp_conn_io_has(conn, on_recv_body))
return (size_t) conn->io->on_recv_body(ptr, len, conn->io);
}
return len;
}
static
oss_error_t ohttp_curl_set_headers(struct ohttp_connection* conn)
{
struct oss_kvlist* headers = &conn->request.headers;
int i;
for (i = 0; i < headers->n; ++i) {
char *header_line = NULL;
struct curl_slist * new_list = NULL;
if (asprintf(&header_line, "%s: %s", headers->items[i].key, headers->items[i].value) == -1)
return OSSE_NO_MEMORY;
ologd("add header = %s", header_line);
new_list = curl_slist_append(conn->curl_headers, header_line);
free(header_line);
if (!new_list)
return OSSE_NO_MEMORY;
conn->curl_headers = new_list;
}
if (curl_easy_setopt(conn->curl, CURLOPT_HTTPHEADER, conn->curl_headers) != CURLE_OK)
return OSSE_NO_MEMORY;
return OSSE_OK;
}
oss_error_t ohttp_request_init(struct ohttp_request *request)
{
request->url = NULL;
if (!oss_kvlist_init(&request->headers, 0))
return OSSE_NO_MEMORY;
if (!oss_kvlist_init(&request->queries, 0))
return OSSE_NO_MEMORY;
return OSSE_OK;
}
void ohttp_request_free(struct ohttp_request *r)
{
if (!r)
return;
oss_kvlist_free(&r->queries);
oss_kvlist_free(&r->headers);
free(r->url);
}
void ohttp_request_clear(struct ohttp_request *r)
{
if (!r)
return;
r->method = OMETHOD_UNKNOWN;
oss_kvlist_clear(&r->queries);
oss_kvlist_clear(&r->headers);
pointer_clear(&r->url);
}
void ohttp_response_clear(struct ohttp_response *r)
{
if (!r)
return;
r->status = OSSE_UNKNOWN;
pointer_clear(&r->reqid);
oss_kvlist_clear(&r->headers);
oss_kvlist_clear(&r->edetails);
oss_buffer_clear(&r->ebody);
}
void ohttp_response_free(struct ohttp_response *r)
{
if (!r)
return;
free(r->reqid);
oss_kvlist_free(&r->headers);
oss_kvlist_free(&r->edetails);
oss_buffer_free(&r->ebody);
}
oss_error_t ohttp_response_init(struct ohttp_response *response)
{
response->status = OSSE_UNKNOWN;
if (!oss_kvlist_init(&response->headers, 0))
return OSSE_NO_MEMORY;
if (!oss_buffer_init(&response->ebody, 0))
return OSSE_NO_MEMORY;
return OSSE_OK;
}
void ohttp_io_free(struct ohttp_io *io)
{
if (io && io->free)
io->free(io);
}
void ohttp_memio_free(void *self)
{
struct ohttp_memio *io = (struct ohttp_memio *) self;
oss_buffer_free(&io->send_buffer);
oss_buffer_free(&io->recv_buffer);
}
oss_i64 ohttp_memio_on_send_body(char *p, size_t len, void *self)
{
struct ohttp_memio *io = (struct ohttp_memio *) self;
int nr_send = -1;
int nr_total = io->send_buffer.n;
ologd("len=%d send_offset=%d nr_total=%d", (int)len, io->send_offset, nr_total);
if (io->send_offset > nr_total)
return nr_send;
if (io->send_offset == nr_total)
return 0;
if (io->send_offset + (int) len > nr_total)
nr_send = nr_total - io->send_offset;
else
nr_send = len;
memcpy(p, io->send_buffer.data + io->send_offset, nr_send);
io->send_offset += nr_send;
return nr_send;
}
oss_i64 ohttp_memio_on_recv_body(char *p, size_t len, void *self)
{
struct ohttp_memio *io = (struct ohttp_memio *) self;
if (oss_buffer_append(&io->recv_buffer, p, len))
return len;
else
return 0;
}
oss_error_t ohttp_memio_end_recv_body(void *self)
{
struct ohttp_memio *io = (struct ohttp_memio *) self;
if (oss_buffer_append_zero(&io->recv_buffer))
return OSSE_OK;
else
return OSSE_NO_MEMORY;
}
/* the naming is wrong? */
struct ohttp_memio *ohttp_memio_send_create(const char *ptr, int size)
{
struct ohttp_memio *io = calloc(1, sizeof(*io));
if (!io)
return NULL;
if (!oss_buffer_assign(&io->send_buffer, ptr, size)) {
free(io);
return NULL;
}
io->super.on_send_body = &ohttp_memio_on_send_body;
io->super.free = &ohttp_memio_free;
return io;
}
struct ohttp_memio *ohttp_memio_recv_create()
{
struct ohttp_memio *io = calloc(1, sizeof(*io));
if (!io)
return NULL;
io->super.on_recv_body = &ohttp_memio_on_recv_body;
io->super.end_recv_body = &ohttp_memio_end_recv_body;
io->super.free = &ohttp_memio_free;
return io;
}
struct ohttp_connection *ohttp_connection_create(const char *region, const char *host, int port)
{
struct ohttp_connection *conn = calloc(1, sizeof(*conn));
if (!conn)
return NULL;
conn->region = strdup(region);
conn->host = strdup(host);
conn->port = port;
conn->curl = curl_easy_init();
if (ohttp_request_init(&conn->request) != OSSE_OK)
goto error;
if (ohttp_response_init(&conn->response) != OSSE_OK)
goto error;
return conn;
error:
ohttp_connection_free_all(conn);
return NULL;
}
void ohttp_connection_free_all(struct ohttp_connection *conn)
{
free(conn->region);
free(conn->host);
free(conn->cred.id);
free(conn->cred.key);
ohttp_request_free(&conn->request);
ohttp_response_free(&conn->response);
ohttp_io_free(conn->io);
curl_easy_cleanup(conn->curl);
curl_slist_free_all(conn->curl_headers);
free(conn);
}
oss_error_t ohttp_init()
{
CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
return (code == CURLE_OK) ? OSSE_OK : OSS_CURLE(code);
}
const char * ohttp_method_string(enum ohttp_method method)
{
switch (method) {
case OMETHOD_DELETE:
return "DELETE";
case OMETHOD_GET:
return "GET";
case OMETHOD_HEAD:
return "HEAD";
case OMETHOD_PUT:
return "PUT";
}
return "UNKNOWN";
}
const char * ohttp_request_get_header(struct ohttp_request *request, const char *key)
{
struct oss_kv *header = oss_kvlist_ifind(&request->headers, key);
return header ? header->value : "";
}
static
char * sign_buffer_appendln(struct oss_buffer *buffer, const char *str)
{
char *back;
char *ret = oss_buffer_append(buffer, str, strlen(str) + 1);
if (!ret)
return ret;
back = oss_buffer_back(buffer);
*back = '\n';
return ret;
}
static
char * sign_buffer_append(struct oss_buffer *buffer, const char *str)
{
return oss_buffer_append(buffer, str, strlen(str));
}
/* TODO: MING: optimize this function */
static
char * sign_buffer_append_header(struct oss_buffer *buffer, struct oss_kv *kv)
{
char *norm_key = str_duplower(kv->key);
char *kv_string = NULL;
char *ret = NULL;
if (!norm_key)
goto error;
if (asprintf(&kv_string, "%s:%s", norm_key, kv->value) == -1)
goto error;
ret = sign_buffer_appendln(buffer, kv_string);
error:
free(norm_key);
free(kv_string);
return ret;
}
static
char * sign_buffer_append_query(struct oss_buffer *buffer, struct oss_kv *kv, int *first_query)
{
if (*first_query) {
if (!sign_buffer_append(buffer, "?"))
return NULL;
*first_query = 0;
} else {
if (!sign_buffer_append(buffer, "&"))
return NULL;
}
if (kv->value[0]) {
if (!sign_buffer_append(buffer, kv->key))
return NULL;
if (!sign_buffer_append(buffer, "="))
return NULL;
return sign_buffer_append(buffer, kv->value);
} else {
return sign_buffer_append(buffer, kv->key);
}
}
static const char *s_subresources[] = {
"uploadId", "uploads", "partNumber",
"acl", "delete", "website", "location", "qos", "referer", "logging", "cors", "lifecycle",
"response-content-type",
"response-content-language",
"response-cache-control",
"response-content-encoding",
"response-expires",
"response-content-disposition",
NULL
};
int ohttp_is_subresource(const char *str)
{
const char **sub;
for (sub = &s_subresources[0]; *sub; sub++) {
if (strcmp(str, *sub) == 0)
return 1;
}
return 0;
}
/* TODO: MING: sort headers, subresources before this function */
/* TODO: MING: make it better */
char * ohttp_get_string_to_sign(struct ohttp_request *request, const char *bucket, const char *object)
{
char *string_to_sign = NULL;
struct oss_kvlist *headers = &request->headers;
struct oss_kvlist *queries = &request->queries;
int first_query = 1;
int i;
struct oss_buffer s;
oss_buffer_init(&s, 1024);
if (!sign_buffer_appendln(&s, ohttp_method_string(request->method)))
goto error;
if (!sign_buffer_appendln(&s, ohttp_request_get_header(request, "content-md5")))
goto error;
if (!sign_buffer_appendln(&s, ohttp_request_get_header(request, "content-type")))
goto error;
if (!sign_buffer_appendln(&s, ohttp_request_get_header(request, "date")))
goto error;
for (i = 0; i < headers->n; i++) {
if (istarts_with(headers->items[i].key, "x-oss-")) {
if (!sign_buffer_append_header(&s, &headers->items[i]))
goto error;
}
}
if (!sign_buffer_append(&s, "/"))
goto error;
if (bucket) {
if (!sign_buffer_append(&s, bucket))
goto error;
if (!sign_buffer_append(&s, "/"))
goto error;
if (object && !sign_buffer_append(&s, object))
goto error;
}
for (i = 0; i < queries->n; i++) {
if (ohttp_is_subresource(queries->items[i].key)) {
ologd("ohttp_get_string_to_sign subresource:%s", queries->items[i].key);
if (!sign_buffer_append_query(&s, &queries->items[i], &first_query))
goto error;
}
}
string_to_sign = oss_buffer_detach_as_string(&s);
ologd("ohttp_get_string_to_sign string_to_sign:%s", string_to_sign);
error:
oss_buffer_free(&s);
return string_to_sign;
}
char *calculate_signature(struct oss_credential *cred, const char *string_to_sign)
{
char *binary_sign = malloc(EVP_MAX_MD_SIZE);
unsigned int binary_len;
int b64_strlen;
char *b64_sign = NULL;
if (!binary_sign)
return NULL;
HMAC(EVP_sha1(), cred->key, strlen(cred->key), string_to_sign, strlen(string_to_sign), binary_sign, &binary_len);
b64_sign = base64(binary_sign, binary_len, &b64_strlen);
free(binary_sign);
return b64_sign;
}
char * ohttp_request_make_query_string(struct ohttp_request *request)
{
struct oss_kvlist *queries = &request->queries;
char *query_string = NULL;
struct oss_buffer b;
int i;
if (!queries->n)
return strdup("");
if (!oss_buffer_init(&b, 16))
return NULL;
if (!oss_buffer_append(&b, "?", 1))
goto error;
for (i = 0; i < queries->n; i++) {
struct oss_kv *kv = &queries->items[i];
if (kv->value[0]) {
if (!oss_buffer_append(&b, kv->key, strlen(kv->key)))
goto error;
if (!oss_buffer_append(&b, "=", 1))
goto error;
if (!oss_buffer_append(&b, kv->value, strlen(kv->value)))
goto error;
} else {
if (!oss_buffer_append(&b, kv->key, strlen(kv->key)))
goto error;
}
}
return oss_buffer_detach_as_string(&b);
error:
oss_buffer_free(&b);
return NULL;
}
/* TODO: MING: unify convention for naming 'make', 'gen' etc. For example, make may mean make internal member. */
oss_error_t ohttp_make_url(struct ohttp_connection *conn, const char *bucket, const char *object)
{
oss_error_t status = OSSE_NO_MEMORY;
struct ohttp_request *request = &conn->request;
char *encoded_object = NULL;
char *query = NULL;
if (request->queries.n) {
if (!(query = ohttp_request_make_query_string(request)))
goto error;
}
if (object) {
if (!(encoded_object = url_encode(object)))
goto error;
if (asprintf(&request->url, "http://%s.%s.%s:%d/%s%s",
bucket, conn->region, conn->host, conn->port, object,
query ? query : "") == -1)
goto error;
} else if (bucket) {
if (asprintf(&request->url, "http://%s.%s.%s:%d/%s",
bucket, conn->region, conn->host, conn->port,
query ? query : "") == -1) {
goto error;
}
} else {
if (asprintf(&request->url, "http://%s.%s:%d/%s",
conn->region, conn->host, conn->port,
query ? query : "") == -1)
goto error;
}
status = OSSE_OK;
error:
free(encoded_object);
free(query);
return status;
}
oss_error_t ohttp_make_auth_header(struct ohttp_request *request, struct oss_credential *cred, const char *bucket, const char *object)
{
char *string_to_sign = NULL;
char *signature = NULL;
char *auth_value = NULL;
oss_error_t status = OSSE_NO_MEMORY;
if (!(string_to_sign = ohttp_get_string_to_sign(request, bucket, object)))
goto error;
if (!(signature = calculate_signature(cred, string_to_sign)))
goto error;
if (asprintf(&auth_value, "OSS %s:%s", cred->id, signature) == -1)
goto error;
ologd("string_to_sign = %s", string_to_sign);
ologd("auth_value = %s", auth_value);
if (!oss_kvlist_append(&request->headers, "Authorization", auth_value))
goto error;
status = OSSE_OK;
error:
free(string_to_sign);
free(signature);
free(auth_value);
return status;
}
/* TODO: MING: the end of this func is not confirmed to setup_curl ... */
static
oss_error_t ohttp_setup_curl(struct ohttp_connection *conn, enum ohttp_method method)
{
CURLcode curl_status;
oss_error_t status = OSSE_UNKNOWN;
x_easy_setopt(CURLOPT_NOPROGRESS, 1);
x_easy_setopt(CURLOPT_FOLLOWLOCATION, 1);
x_easy_setopt(CURLOPT_USERAGENT, s_user_agent);
x_easy_setopt(CURLOPT_HEADERDATA, conn);
x_easy_setopt(CURLOPT_HEADERFUNCTION, &ohttp_curl_header_function);
x_easy_setopt(CURLOPT_READDATA, conn);
x_easy_setopt(CURLOPT_READFUNCTION, &ohttp_curl_read_function);
x_easy_setopt(CURLOPT_WRITEDATA, conn);
x_easy_setopt(CURLOPT_WRITEFUNCTION, &ohttp_curl_write_function);
if ((status = ohttp_curl_set_headers(conn)) != OSSE_OK) {
ologe("curl set headders failed");
return status;
}
x_easy_setopt(CURLOPT_URL, conn->request.url);
switch (method) {
case OMETHOD_DELETE:
x_easy_setopt(CURLOPT_CUSTOMREQUEST, "DELETE");
break;
case OMETHOD_HEAD:
x_easy_setopt(CURLOPT_NOBODY, 1);
break;
case OMETHOD_GET:
break;
case OMETHOD_PUT:
x_easy_setopt(CURLOPT_UPLOAD, 1);
break;
default:
return OSSE_IMPOSSIBLE;
}
curl_status = curl_easy_perform(conn->curl);
if (curl_status != CURLE_OK) {
ologe("curl status is %d\n", curl_status);
return OSS_CURLE(curl_status);
}
set_response_status(conn);
if (ohttp_conn_io_has(conn, end_recv_body))
status = conn->io->end_recv_body(conn->io);
return status;
}
oss_error_t ohttp_request_make_date(struct ohttp_request *request)
{
char date_string[64];
time_t now = time(NULL);
strftime(date_string, sizeof(date_string), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
if (!oss_kvlist_append(&request->headers, "date", date_string))
return OSSE_NO_MEMORY;
return OSSE_OK;
}
int is_http_success(int status)
{
return status / 100 == 2;
}
void ohttp_set_io(struct ohttp_connection *conn, struct ohttp_io *io)
{
ohttp_io_free(conn->io);
conn->io = io;
}
oss_error_t ohttp_set_credential(struct ohttp_connection *conn, const char *access_id, const char *access_key)
{
char *new_id = strdup(access_id);
char *new_key = strdup(access_key);
if (!new_id || !new_key) {
free(new_id);
free(new_key);
return OSSE_NO_MEMORY;
}
free(conn->cred.id);
free(conn->cred.key);
conn->cred.id = new_id;
conn->cred.key = new_key;
return OSSE_OK;
}
oss_error_t ohttp_request(struct ohttp_connection *conn,
enum ohttp_method method,
const char *bucket,
const char *object)
{
oss_error_t status;
struct ohttp_request *request = &conn->request;
request->method = method;
if ((status = ohttp_request_make_date(request)) != OSSE_OK) {
ologe("failed to make date: %d", status);
return status;
}
if ((status = ohttp_make_url(conn, bucket, object)) != OSSE_OK) {
ologe("failed to make url");
return status;
}
oss_kvlist_isort(&request->headers);
oss_kvlist_sort(&request->queries);
if ((status = ohttp_make_auth_header(request, &conn->cred, bucket, object)) != OSSE_OK) {
ologe("failed to make auth header");
return status;
}
if ((status = ohttp_setup_curl(conn, method)) != OSSE_OK) {
ologe("failed to setup curl");
return status;
}
if (!is_http_success(conn->response.status)) {
ologd("http error: %d", conn->response.status);
return conn->response.status;
}
return OSSE_OK;
}
void ohttp_connection_clear(struct ohttp_connection *conn)
{
ohttp_request_clear(&conn->request);
ohttp_response_clear(&conn->response);
curl_easy_reset(conn->curl);
curl_slist_free_all(conn->curl_headers);
conn->curl_headers = NULL;
}