Account for binary HTTP responses

This commit is contained in:
Struma 2021-03-27 23:34:46 -04:00 committed by Roza
parent 44dda759a4
commit d7816c121b

View file

@ -56,7 +56,7 @@ RB_METHOD(httpGet) {
auto res = req.get();
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("status")), INT2NUM(res.status()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new(res.body().c_str(), res.body().length()));
rb_hash_aset(ret, ID2SYM(rb_intern("headers")), stringMap2hash(res.headers()));
} catch (Exception &e) {
raiseRbExc(e);
@ -85,7 +85,7 @@ RB_METHOD(httpPost) {
auto res = req.post(postData);
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("status")), INT2NUM(res.status()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new(res.body().c_str(), res.body().length()));
rb_hash_aset(ret, ID2SYM(rb_intern("headers")), stringMap2hash(res.headers()));
} catch (Exception &e) {
raiseRbExc(e);
@ -114,7 +114,7 @@ RB_METHOD(httpPostBody) {
auto res = req.post(RSTRING_PTR(body), RSTRING_PTR(ctype));
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("status")), INT2NUM(res.status()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new(res.body().c_str(), res.body().length()));
rb_hash_aset(ret, ID2SYM(rb_intern("headers")), stringMap2hash(res.headers()));
} catch (Exception &e) {
raiseRbExc(e);