Method: Curl::Easy#http_patch
- Defined in:
- ext/curb_easy.c
#http_patch("url = encoded%20form%20data;and=so%20on") ⇒ true #http_patch("url = encoded%20form%20data", "and = so%20on", ...) ⇒ true #http_patch("url = encoded%20form%20data", Curl: :PostField, "and = so%20on", ...) ⇒ true #http_patch(Curl: :PostField, Curl: :PostField..., Curl: :PostField) ⇒ true
PATCH the specified formdata to the currently configured URL using the current options set for this Curl::Easy instance. This method always returns true, or raises an exception (defined under Curl::Err) on error.
When multipart_form_post is true the multipart logic is used; otherwise, the arguments are joined into a raw PATCH body.
3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 |
# File 'ext/curb_easy.c', line 3300
static VALUE ruby_curl_easy_perform_patch(int argc, VALUE *argv, VALUE self) {
ruby_curl_easy *rbce;
CURL *curl;
int i;
VALUE args_ary;
rb_scan_args(argc, argv, "*", &args_ary);
TypedData_Get_Struct(self, ruby_curl_easy, &ruby_curl_easy_data_type, rbce);
curl = rbce->curl;
/* Clear the error buffer */
memset(rbce->err_buf, 0, CURL_ERROR_SIZE);
/* Set the custom HTTP method to PATCH */
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");
if (rbce->multipart_form_post) {
VALUE ret;
struct curl_httppost *first = NULL, *last = NULL;
/* Build the multipart form (same logic as for POST) */
for (i = 0; i < argc; i++) {
if (rb_obj_is_instance_of(argv[i], cCurlPostField)) {
append_to_form(argv[i], &first, &last);
} else if (rb_type(argv[i]) == T_ARRAY) {
long j, argv_len = RARRAY_LEN(argv[i]);
for (j = 0; j < argv_len; ++j) {
if (rb_obj_is_instance_of(rb_ary_entry(argv[i], j), cCurlPostField)) {
append_to_form(rb_ary_entry(argv[i], j), &first, &last);
} else {
rb_raise(eCurlErrInvalidPostField,
"You must use PostFields only with multipart form posts");
return Qnil;
}
}
} else {
rb_raise(eCurlErrInvalidPostField,
"You must use PostFields only with multipart form posts");
return Qnil;
}
}
/* Disable the POST flag */
curl_easy_setopt(curl, CURLOPT_POST, 0);
/* Use the built multipart form as the request body */
curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
struct easy_form_perform_args perform_args = { curl, first };
ret = rb_ensure(call_easy_perform, self, ensure_free_form_post, (VALUE)&perform_args);
return ret;
} else {
/* Join arguments into a raw PATCH body */
VALUE patch_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp);
if (patch_body == Qnil) {
rb_raise(eCurlErrError, "Failed to join arguments");
return Qnil;
} else {
if (rb_type(patch_body) == T_STRING && RSTRING_LEN(patch_body) > 0) {
ruby_curl_easy_post_body_set(self, patch_body);
}
/* If postdata_buffer is still nil, set it so that the PATCH header is enabled */
if (rb_easy_nil("postdata_buffer")) {
ruby_curl_easy_post_body_set(self, patch_body);
}
return rb_funcall(self, rb_intern("perform"), 0);
}
}
}
|