@@ -36,6 +36,7 @@ interface
3636 procedure SetUrl (aData : PAnsiChar); overload;
3737 procedure SetUrl (aData : RawByteString); overload;
3838 procedure SetUrl (aData : UnicodeString); overload;
39+ procedure SetUrl (aData : ICurlStringBuilder); overload;
3940
4041 // / Sets a CA file for SSL
4142 procedure SetCaFile (aData : PAnsiChar); overload;
@@ -179,6 +180,7 @@ TEasyCurlImpl = class (TInterfacedObject, ICurl)
179180 procedure SetUrl (aData : PAnsiChar); overload; inline;
180181 procedure SetUrl (aData : RawByteString); overload; inline;
181182 procedure SetUrl (aData : UnicodeString); overload; inline;
183+ procedure SetUrl (aData : ICurlStringBuilder); overload; inline;
182184
183185 procedure SetCaFile (aData : PAnsiChar); overload; inline;
184186 procedure SetCaFile (aData : RawByteString); overload; inline;
@@ -225,15 +227,6 @@ TEasyCurlImpl = class (TInterfacedObject, ICurl)
225227 // / reference-counting, use TEasyCurlImpl.Create(someCurl).
226228 function Clone : ICurl;
227229
228- class function StreamWrite (
229- var Buffer;
230- Size, NItems : NativeUInt;
231- OutStream : pointer) : NativeUInt; cdecl; static;
232- class function StreamRead (
233- var Buffer;
234- Size, NItems : NativeUInt;
235- OutStream : pointer) : NativeUInt; cdecl; static;
236-
237230 property Form : ICurlCustomForm read GetForm write SetForm;
238231
239232 procedure CloseStreams ;
@@ -438,6 +431,11 @@ procedure TEasyCurlImpl.SetUrl(aData : UnicodeString);
438431 SetOpt(CURLOPT_URL, aData);
439432end ;
440433
434+ procedure TEasyCurlImpl.SetUrl (aData : ICurlStringBuilder);
435+ begin
436+ SetUrl(aData.Build);
437+ end ;
438+
441439procedure TEasyCurlImpl.SetCaFile (aData : PAnsiChar);
442440begin
443441 SetOpt(CURLOPT_CAINFO, aData);
@@ -473,40 +471,25 @@ procedure TEasyCurlImpl.SetUserAgent(aData : UnicodeString);
473471 SetOpt(CURLOPT_USERAGENT, PAnsiChar(UTF8Encode(aData)));
474472end ;
475473
476- class function TEasyCurlImpl.StreamWrite (
477- var Buffer;
478- Size, NItems : NativeUInt;
479- OutStream : pointer) : NativeUInt; cdecl;
480- begin
481- Result := TStream(OutStream).Write(Buffer, Size * NItems);
482- end ;
483-
484-
485- class function TEasyCurlImpl.StreamRead (
486- var Buffer;
487- Size, NItems : NativeUInt;
488- OutStream : pointer) : NativeUInt; cdecl;
489- begin
490- Result := TStream(OutStream).Read(Buffer, Size * NItems);
491- end ;
492-
493-
494474procedure TEasyCurlImpl.SetRecvStream (aData : TStream; aFlags : TCurlStreamFlags);
495475begin
496476 fRecvStream.Assign(aData, aFlags);
497477 SetOpt(CURLOPT_WRITEDATA, aData);
498478 if aData = nil
499479 then SetOpt(CURLOPT_WRITEFUNCTION, nil )
500- else SetOpt(CURLOPT_WRITEFUNCTION, @StreamWrite );
480+ else SetOpt(CURLOPT_WRITEFUNCTION, @CurlStreamWrite );
501481end ;
502482
503483
504484procedure TEasyCurlImpl.SetSendStream (aData : TStream; aFlags : TCurlStreamFlags);
505485begin
486+ // Form and sender stream exclude each other
487+ fForm := nil ;
506488 fSendStream.Assign(aData, aFlags);
507489 SetOpt(CURLOPT_READDATA, aData);
508- // Don’t set NULL to read function, as the function may be needed by form
509- SetOpt(CURLOPT_READFUNCTION, @StreamRead);
490+ if aData = nil
491+ then SetOpt(CURLOPT_READFUNCTION, nil )
492+ else SetOpt(CURLOPT_READFUNCTION, @CurlStreamRead);
510493end ;
511494
512495procedure TEasyCurlImpl.SetHeaderStream (aData : TStream; aFlags : TCurlStreamFlags);
@@ -515,7 +498,7 @@ procedure TEasyCurlImpl.SetHeaderStream(aData : TStream; aFlags : TCurlStreamFla
515498 SetOpt(CURLOPT_HEADERDATA, aData);
516499 if aData = nil
517500 then SetOpt(CURLOPT_HEADERFUNCTION, nil )
518- else SetOpt(CURLOPT_HEADERFUNCTION, @StreamWrite );
501+ else SetOpt(CURLOPT_HEADERFUNCTION, @CurlStreamWrite );
519502end ;
520503
521504function TEasyCurlImpl.GetResponseCode : longint;
@@ -602,12 +585,14 @@ procedure TEasyCurlImpl.SetSslVerifyPeer(aData : boolean);
602585
603586procedure TEasyCurlImpl.SetForm (aForm : ICurlCustomForm);
604587begin
588+ // Form and sender stream exclude each other
589+ fSendStream.Destroy;
605590 if aForm <> nil then begin
606591 SetOpt(CURLOPT_HTTPPOST, aForm.RawValue);
607- if aForm.DoesUseStream
608- then SetOpt(CURLOPT_READFUNCTION, @StreamRead);
592+ SetOpt(CURLOPT_READFUNCTION, @aForm.ReadFunction);
609593 end else begin
610594 SetOpt(CURLOPT_HTTPPOST, nil );
595+ SetOpt(CURLOPT_READFUNCTION, nil );
611596 end ;
612597 fForm := aForm;
613598end ;
0 commit comments