diff --git a/lib/Curl.ts b/lib/Curl.ts index 493fbcd54..145c9802e 100644 --- a/lib/Curl.ts +++ b/lib/Curl.ts @@ -28,6 +28,7 @@ import { DataCallbackOptions, ProgressCallbackOptions, StringListOptions, + BlobListOptions, CurlOptionName, SpecificOptions, CurlOptionValueType, @@ -1226,6 +1227,13 @@ interface Curl { * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) */ setOpt(option: StringListOptions, value: string[] | null): this + /** + * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. + * + * + * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) + */ + setOpt(option: BlobListOptions, value: Buffer | string | null): this /** * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. * diff --git a/lib/generated/CurlInfo.ts b/lib/generated/CurlInfo.ts index e206aa0ee..f6e6a339f 100644 --- a/lib/generated/CurlInfo.ts +++ b/lib/generated/CurlInfo.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -// This file was generated by scripts/build-constants.js on 2020-10-11T15:59:27.934Z +// This file was generated by scripts/build-constants.js on 2021-07-23T03:53:26.721Z // Do not edit manually /** diff --git a/lib/generated/CurlOption.ts b/lib/generated/CurlOption.ts index 2fcbcf52c..fd77266e1 100644 --- a/lib/generated/CurlOption.ts +++ b/lib/generated/CurlOption.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -// This file was generated by scripts/build-constants.js on 2020-10-11T15:59:26.976Z +// This file was generated by scripts/build-constants.js on 2021-07-23T03:53:25.898Z // Do not edit manually import { CurlChunk } from '../enum/CurlChunk' @@ -293,7 +293,7 @@ export interface CurlOption { readonly DNS_USE_GLOBAL_CACHE: 'DNS_USE_GLOBAL_CACHE' /** - * Use this DOH server for name resolves. + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ @@ -580,7 +580,7 @@ export interface CurlOption { readonly INTERFACE: 'INTERFACE' /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ @@ -593,6 +593,13 @@ export interface CurlOption { */ readonly ISSUERCERT: 'ISSUERCERT' + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + readonly ISSUERCERT_BLOB: 'ISSUERCERT_BLOB' + /** * Keep sending on HTTP \>= 300 errors. * @@ -985,6 +992,20 @@ export interface CurlOption { */ readonly PROXY_SSL_VERIFYPEER: 'PROXY_SSL_VERIFYPEER' + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + readonly PROXY_SSLCERT: 'PROXY_SSLCERT' + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + readonly PROXY_SSLCERT_BLOB: 'PROXY_SSLCERT_BLOB' + /** * Proxy client cert type. * @@ -999,6 +1020,13 @@ export interface CurlOption { */ readonly PROXY_SSLKEY: 'PROXY_SSLKEY' + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + readonly PROXY_SSLKEY_BLOB: 'PROXY_SSLKEY_BLOB' + /** * Proxy client key type. * @@ -1398,6 +1426,13 @@ export interface CurlOption { */ readonly SSLCERT: 'SSLCERT' + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + readonly SSLCERT_BLOB: 'SSLCERT_BLOB' + /** * Client cert type. * @@ -1426,6 +1461,13 @@ export interface CurlOption { */ readonly SSLKEY: 'SSLKEY' + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + readonly SSLKEY_BLOB: 'SSLKEY_BLOB' + /** * Client key type. * @@ -1954,7 +1996,7 @@ export const CurlOptionCamelCaseMap = { dnsUseGlobalCache: 'DNS_USE_GLOBAL_CACHE', /** - * Use this DOH server for name resolves. + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ @@ -2241,7 +2283,7 @@ export const CurlOptionCamelCaseMap = { interface: 'INTERFACE', /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ @@ -2254,6 +2296,13 @@ export const CurlOptionCamelCaseMap = { */ issuerCert: 'ISSUERCERT', + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + issuerCertBlob: 'ISSUERCERT_BLOB', + /** * Keep sending on HTTP \>= 300 errors. * @@ -2646,6 +2695,20 @@ export const CurlOptionCamelCaseMap = { */ proxySslVerifyPeer: 'PROXY_SSL_VERIFYPEER', + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + proxySslCert: 'PROXY_SSLCERT', + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + proxySslCertBlob: 'PROXY_SSLCERT_BLOB', + /** * Proxy client cert type. * @@ -2660,6 +2723,13 @@ export const CurlOptionCamelCaseMap = { */ proxySslKey: 'PROXY_SSLKEY', + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + proxySslKeyBlob: 'PROXY_SSLKEY_BLOB', + /** * Proxy client key type. * @@ -3059,6 +3129,13 @@ export const CurlOptionCamelCaseMap = { */ sslCert: 'SSLCERT', + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + sslCertBlob: 'SSLCERT_BLOB', + /** * Client cert type. * @@ -3087,6 +3164,13 @@ export const CurlOptionCamelCaseMap = { */ sslKey: 'SSLKEY', + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + sslKeyBlob: 'SSLKEY_BLOB', + /** * Client key type. * @@ -3438,6 +3522,7 @@ export type CurlOptionName = | 'INTERFACE' | 'IPRESOLVE' | 'ISSUERCERT' + | 'ISSUERCERT_BLOB' | 'KEEP_SENDING_ON_ERROR' | 'KEYPASSWD' | 'KRBLEVEL' @@ -3494,8 +3579,11 @@ export type CurlOptionName = | 'PROXY_SSL_OPTIONS' | 'PROXY_SSL_VERIFYHOST' | 'PROXY_SSL_VERIFYPEER' + | 'PROXY_SSLCERT' + | 'PROXY_SSLCERT_BLOB' | 'PROXY_SSLCERTTYPE' | 'PROXY_SSLKEY' + | 'PROXY_SSLKEY_BLOB' | 'PROXY_SSLKEYTYPE' | 'PROXY_SSLVERSION' | 'PROXY_TLS13_CIPHERS' @@ -3553,10 +3641,12 @@ export type CurlOptionName = | 'SSL_VERIFYPEER' | 'SSL_VERIFYSTATUS' | 'SSLCERT' + | 'SSLCERT_BLOB' | 'SSLCERTTYPE' | 'SSLENGINE' | 'SSLENGINE_DEFAULT' | 'SSLKEY' + | 'SSLKEY_BLOB' | 'SSLKEYTYPE' | 'SSLVERSION' | 'SUPPRESS_CONNECT_HEADERS' @@ -3612,10 +3702,18 @@ export type StringListOptions = | 'QUOTE' | 'RESOLVE' | 'TELNETOPTIONS' +export type BlobListOptions = + | 'ISSUERCERT_BLOB' + | 'SSLKEY_BLOB' + | 'SSLCERT_BLOB' + | 'PROXY_SSLCERT_BLOB' + | 'PROXY_SSLCERT' + | 'PROXY_SSLKEY_BLOB' export type SpecificOptions = | DataCallbackOptions | ProgressCallbackOptions | StringListOptions + | BlobListOptions | 'CHUNK_BGN_FUNCTION' | 'CHUNK_END_FUNCTION' | 'DEBUGFUNCTION' @@ -4181,14 +4279,14 @@ export type CurlOptionValueType = { dnsUseGlobalCache?: string | number | boolean | null /** - * Use this DOH server for name resolves. + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ DOH_URL?: string | number | boolean | null /** - * Use this DOH server for name resolves. + * Use this DoH server for name resolves. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html](https://curl.haxx.se/libcurl/c/CURLOPT_DOH_URL.html) */ @@ -4781,14 +4879,14 @@ export type CurlOptionValueType = { interface?: string | number | boolean | null /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ IPRESOLVE?: CurlIpResolve | null /** - * IP version to resolve to. + * IP version to use. * * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html](https://curl.haxx.se/libcurl/c/CURLOPT_IPRESOLVE.html) */ @@ -4808,6 +4906,20 @@ export type CurlOptionValueType = { */ issuerCert?: string | number | boolean | null + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + ISSUERCERT_BLOB?: string | number | boolean | null + + /** + * Issuer certificate memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_ISSUERCERT_BLOB.html) + */ + issuerCertBlob?: string | number | boolean | null + /** * Keep sending on HTTP \>= 300 errors. * @@ -5608,6 +5720,34 @@ export type CurlOptionValueType = { */ proxySslVerifyPeer?: string | number | boolean | null + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + PROXY_SSLCERT?: string | number | boolean | null + + /** + * Proxy client cert. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT.html) + */ + proxySslCert?: string | number | boolean | null + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + PROXY_SSLCERT_BLOB?: string | number | boolean | null + + /** + * Proxy client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLCERT_BLOB.html) + */ + proxySslCertBlob?: string | number | boolean | null + /** * Proxy client cert type. * @@ -5636,6 +5776,20 @@ export type CurlOptionValueType = { */ proxySslKey?: string | number | boolean | null + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + PROXY_SSLKEY_BLOB?: string | number | boolean | null + + /** + * Proxy client key. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY_SSLKEY_BLOB.html) + */ + proxySslKeyBlob?: string | number | boolean | null + /** * Proxy client key type. * @@ -6452,6 +6606,20 @@ export type CurlOptionValueType = { */ sslCert?: string | number | boolean | null + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + SSLCERT_BLOB?: string | number | boolean | null + + /** + * Client cert memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT_BLOB.html) + */ + sslCertBlob?: string | number | boolean | null + /** * Client cert type. * @@ -6508,6 +6676,20 @@ export type CurlOptionValueType = { */ sslKey?: string | number | boolean | null + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + SSLKEY_BLOB?: string | number | boolean | null + + /** + * Client key memory buffer. + * + * Official libcurl documentation: : [https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) + */ + sslKeyBlob?: string | number | boolean | null + /** * Client key type. * diff --git a/lib/generated/MultiOption.ts b/lib/generated/MultiOption.ts index 2e2aa819f..e09d4a37d 100644 --- a/lib/generated/MultiOption.ts +++ b/lib/generated/MultiOption.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -// This file was generated by scripts/build-constants.js on 2020-10-11T15:59:28.821Z +// This file was generated by scripts/build-constants.js on 2021-07-23T03:53:27.484Z // Do not edit manually /** diff --git a/lib/types/EasyNativeBinding.ts b/lib/types/EasyNativeBinding.ts index 4397fc3fe..75368ca03 100644 --- a/lib/types/EasyNativeBinding.ts +++ b/lib/types/EasyNativeBinding.ts @@ -9,6 +9,7 @@ import { CurlOptionName, DataCallbackOptions, ProgressCallbackOptions, + BlobListOptions, StringListOptions, SpecificOptions, } from '../generated/CurlOption' @@ -147,6 +148,13 @@ export declare class EasyNativeBinding { * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) */ setOpt(option: StringListOptions, value: string[] | null): CurlCode + /** + * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. + * + * + * Official libcurl documentation: [`curl_easy_setopt()`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) + */ + setOpt(option: BlobListOptions, value: ArrayBuffer | string | null): CurlCode /** * Use {@link "Curl".Curl.option|`Curl.option`} for predefined constants. * diff --git a/scripts/build-constants.js b/scripts/build-constants.js index fd092f544..04688fa44 100644 --- a/scripts/build-constants.js +++ b/scripts/build-constants.js @@ -106,7 +106,8 @@ const run = async () => { optionKindMap.progressCallback, )}`, `export type StringListOptions = ${union(optionKindMap.stringList)}`, - `export type SpecificOptions = DataCallbackOptions | ProgressCallbackOptions | StringListOptions | ${union( + `export type BlobListOptions = ${union(optionKindMap.blobList)}`, + `export type SpecificOptions = DataCallbackOptions | ProgressCallbackOptions | StringListOptions | BlobListOptions | ${union( optionKindMap.other, )}`, ] diff --git a/scripts/ci/build-libcurl.sh b/scripts/ci/build-libcurl.sh index 0394ab372..c5de9b951 100755 --- a/scripts/ci/build-libcurl.sh +++ b/scripts/ci/build-libcurl.sh @@ -260,7 +260,6 @@ export LDFLAGS=$LDFLAGS ./configure \ --without-nss \ --without-libpsl \ - --without-libmetalink \ --without-librtmp \ --without-libidn \ --disable-manual \ diff --git a/scripts/data/options.js b/scripts/data/options.js index 70e751df6..f46d0cc01 100644 --- a/scripts/data/options.js +++ b/scripts/data/options.js @@ -13,6 +13,14 @@ const optionKindMap = { 'RESOLVE', 'TELNETOPTIONS', ], + blobList: [ + 'ISSUERCERT_BLOB', + 'SSLKEY_BLOB', + 'SSLCERT_BLOB', + 'PROXY_SSLCERT_BLOB', + 'PROXY_SSLCERT', + 'PROXY_SSLKEY_BLOB', + ], other: [ 'CHUNK_BGN_FUNCTION', 'CHUNK_END_FUNCTION', @@ -50,6 +58,7 @@ const optionKindValueMap = { progressCallback: '((this: EasyNativeBinding, dltotal: number,dlnow: number,ultotal: number,ulnow: number) => number | CurlProgressFunc)', stringList: 'string[]', + blob: 'ArrayBuffer | Buffer | string', /* @TODO Add type definitions, they are on Curl.chunk */ CHUNK_BGN_FUNCTION: '((this: EasyNativeBinding, fileInfo: FileInfo, remains: number) => CurlChunk)', diff --git a/scripts/utils/createSetOptOverloads.js b/scripts/utils/createSetOptOverloads.js index 7c6ccc8a5..07d596f85 100644 --- a/scripts/utils/createSetOptOverloads.js +++ b/scripts/utils/createSetOptOverloads.js @@ -33,6 +33,11 @@ const createSetOptOverloads = (filePath, setOptReturnType = 'CurlCode') => { optionKindValueMap.stringList, setOptReturnType, ), + getSetOptDefinition( + 'BlobListOptions', + optionKindValueMap.blob, + setOptReturnType, + ), ] for (const specificOption of optionKindMap.other) { diff --git a/scripts/utils/curlOptionsBlacklist.js b/scripts/utils/curlOptionsBlacklist.js index 13381ac10..b817d3ec7 100644 --- a/scripts/utils/curlOptionsBlacklist.js +++ b/scripts/utils/curlOptionsBlacklist.js @@ -1,13 +1,5 @@ // This should be kept in sync with the options on src/Curl.cc curlOptionNotImplemented const curlOptionsBlacklist = [ - // TODO: add support for curl_blob - See https://github.com/JCMais/node-libcurl/issues/253 - 'CURLOPT_ISSUERCERT_BLOB', - 'CURLOPT_SSLKEY_BLOB', - 'CURLOPT_SSLCERT_BLOB', - 'CURLOPT_PROXY_SSLCERT_BLOB', - 'CURLOPT_PROXY_SSLCERT', - 'CURLOPT_PROXY_SSLKEY_BLOB', - // probably will be implemented at some time in the future? 'CURLOPT_STREAM_DEPENDS', 'CURLOPT_STREAM_DEPENDS_E', diff --git a/src/Curl.cc b/src/Curl.cc index 904a33f69..271f611dd 100644 --- a/src/Curl.cc +++ b/src/Curl.cc @@ -656,6 +656,16 @@ const std::vector curlInfoLinkedList = { {"CERTINFO", CURLINFO_CERTINFO}, }; +const std::vector curlOptionBlob = { +#if NODE_LIBCURL_VER_GE(7, 71, 0) + {"ISSUERCERT_BLOB", CURLOPT_ISSUERCERT_BLOB}, + {"PROXY_SSLCERT_BLOB", CURLOPT_PROXY_SSLCERT_BLOB}, + {"PROXY_SSLKEY_BLOB", CURLOPT_PROXY_SSLKEY_BLOB}, + {"SSLCERT_BLOB", CURLOPT_SSLCERT_BLOB}, + {"SSLKEY_BLOB", CURLOPT_SSLKEY_BLOB}, +#endif +}; + static void ExportConstants(v8::Local obj, const std::vector& optionGroup, v8::PropertyAttribute attributes) { @@ -688,6 +698,7 @@ NAN_MODULE_INIT(Initialize) { ExportConstants(optionsObj, curlOptionFunction, attributes); ExportConstants(optionsObj, curlOptionLinkedList, attributes); ExportConstants(optionsObj, curlOptionSpecific, attributes); + ExportConstants(optionsObj, curlOptionBlob, attributes); // export infos v8::Local infosObj = Nan::New(); diff --git a/src/Curl.h b/src/Curl.h index 940725499..3fa635b39 100644 --- a/src/Curl.h +++ b/src/Curl.h @@ -44,6 +44,7 @@ extern const std::vector curlOptionFunction; extern const std::vector curlOptionLinkedList; extern const std::vector curlOptionHttpPost; extern const std::vector curlOptionSpecific; +extern const std::vector curlOptionBlob; extern const std::vector curlInfoNotImplemented; extern const std::vector curlInfoString; diff --git a/src/Easy.cc b/src/Easy.cc index 3588a7372..222168605 100755 --- a/src/Easy.cc +++ b/src/Easy.cc @@ -1612,6 +1612,38 @@ NAN_METHOD(Easy::SetOpt) { break; } + + // check if option is a blob, and the value is correct + } else if ((optionId = IsInsideCurlConstantStruct(curlOptionBlob, opt))) { +#if NODE_LIBCURL_VER_GE(7, 71, 0) + if (value->IsNull()) { + setOptRetCode = curl_easy_setopt(obj->ch, static_cast(optionId), NULL); + } else if (value->IsString()) { + Nan::Utf8String utf8StringValue(value); + + size_t length = static_cast(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(optionId), &blob); + } else if (node::Buffer::HasInstance(value)) { + struct curl_blob blob; + blob.data = node::Buffer::Data(value); + blob.len = node::Buffer::Length(value); + blob.flags = CURL_BLOB_COPY; + + setOptRetCode = curl_easy_setopt(obj->ch, static_cast(optionId), &blob); + } else { + Nan::ThrowTypeError("Option value must be a string or Buffer."); + return; + } +#else + Nan::ThrowError("Blob options require curl 7.71 or newer."); + return; +#endif } info.GetReturnValue().Set(setOptRetCode); diff --git a/test/curl/setOpt.spec.ts b/test/curl/setOpt.spec.ts index 913c7f06d..f8b9d5a07 100644 --- a/test/curl/setOpt.spec.ts +++ b/test/curl/setOpt.spec.ts @@ -11,6 +11,11 @@ import { Curl } from '../../lib' const url = `http://${host}:${port}/` +const pemFormattedPrivateKey = `-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEILeQs78xyjaibQhUrMQJ1Fsxeb8LAaDPeat8SGEFEVQ+ +-----END PRIVATE KEY----- +` + let curl: Curl describe('setOpt()', () => { @@ -57,6 +62,19 @@ describe('setOpt()', () => { curl.setOpt('WRITEFUNCTION', null) }) + it('should be able to set blob value back to null', () => { + curl.setOpt('SSLKEY_BLOB', Buffer.from([])) + curl.setOpt('SSLKEY_BLOB', null) + }) + + it('should be able to set blob value to buffer', () => { + curl.setOpt('SSLKEY_BLOB', Buffer.from(pemFormattedPrivateKey, 'utf-8')) + }) + + it('should be able to set blob value to string', () => { + curl.setOpt('SSLKEY_BLOB', pemFormattedPrivateKey) + }) + it('should not accept invalid argument type', () => { const optionsToTest = [ ['URL', 0],