Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support curl_blob options #300

Merged
merged 2 commits into from
Jul 24, 2021

Conversation

johnwchadwick
Copy link
Contributor

Fixes #253.

Because I ran gen:constants, a bunch of new constants were added from curl.se. Should I:

  • update curl first separately/wait for curl to be updated first separately and rebase this?
  • manually adjust generated options to only include newly-enabled BLOB options?
  • do nothing, keep the new options?

I am new to the project and not sure what the best course of action is.

Copy link
Owner

@JCMais JCMais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnwchadwick just some minor comments, everything else looks great. Thanks so much for the PR!

Related to your question, go with options 2:

manually adjust generated options to only include newly-enabled BLOB options?

I will add a note related to that to the CONTRIBUTING docs. If you have any other feedback related to the Developer Experience, please do let me know, I would love to improve it.

src/Easy.cc Outdated
Comment on lines 1622 to 1631
Nan::Utf8String value(value);

size_t length = static_cast<size_t>(value.length());

struct curl_blob blob;
blob.data = *value;
blob.len = length;
blob.flags = CURL_BLOB_COPY;

setOptRetCode = curl_easy_setopt(obj->ch, static_cast<CURLoption>(optionId), &blob);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Nan::Utf8String value(value);
size_t length = static_cast<size_t>(value.length());
struct curl_blob blob;
blob.data = *value;
blob.len = length;
blob.flags = CURL_BLOB_COPY;
setOptRetCode = curl_easy_setopt(obj->ch, static_cast<CURLoption>(optionId), &blob);
Nan::Utf8String utf8StringValue(value);
size_t length = static_cast<size_t>(utf8StringValue.length());
struct curl_blob blob;
blob.data = *utf8StringValue;
blob.len = length;
blob.flags = CURL_BLOB_COPY;
setOptRetCode = curl_easy_setopt(obj->ch, static_cast<CURLoption>(optionId), &blob);

Just to make it more clear what value is and to not use the same variable name that was declared in the outer scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

struct curl_blob blob;
blob.data = *value;
blob.len = length;
blob.flags = CURL_BLOB_COPY;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this could give a small perf hit down the road (for bigger payloads)? Honest question, I'm ok with just copying the data for now.

Another approach would be to keep the data internally. Check the ToFree data structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be ideal to not copy the data if it isn't needed, but I worry more about correctness than performance. Particularly because Buffers are mutable, but also because copying frees us of having to worry about the memory management of all of these containers. Even the CA certs bundle is only around 200 KiB, which isn't too bad. So I think for now, I would prefer to punt on it, although it would probably be worth looking into.

Comment on lines +60 to +68
it('should be able to set blob value back to null', () => {
curl.setOpt('SSLKEY_BLOB', Buffer.from([]))
curl.setOpt('SSLKEY_BLOB', null)
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another 2 test cases for:

  • String value
  • Buffer with data (the above one is empty)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

libmetalink is no longer supported by curl; specifying this option is
now an error as of curl 7.78.0/265b14d6.
@JCMais JCMais merged commit 2da5471 into JCMais:develop Jul 24, 2021
@JCMais
Copy link
Owner

JCMais commented Jul 24, 2021

Thanks @johnwchadwick !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for CURLOPT_*_BLOB options
2 participants