1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-11-27 22:18:36 +02:00

Main build (Jenkins)

This commit is contained in:
Vitaly the Alpaca (bot)
2025-04-25 21:52:05 +03:00
parent bc60b480ab
commit 58d505c297
35 changed files with 8380 additions and 7496 deletions

View File

@@ -0,0 +1,4 @@
{
"URL": "https://httpbin.org",
"Image": "https://api.athenaeum.digital/test_data/picture.jpg"
}

View File

@@ -0,0 +1,4 @@
{
"URL": "https://httpbin.org",
"Image": "https://api.athenaeum.digital/test_data/picture.jpg"
}

View File

@@ -0,0 +1,3 @@
{
"URL": "https://httpbin.org"
}

View File

@@ -0,0 +1,3 @@
{
"URL": "https://httpbin.org"
}

View File

@@ -0,0 +1,3 @@
{
"URL": "https://httpbin.org"
}

View File

@@ -0,0 +1,4 @@
{
"URL": "https://httpbin.org",
"Image": "https://api.athenaeum.digital/test_data/picture.jpg"
}

View File

@@ -0,0 +1,13 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
.AddMultipartFormDataField("Field1", "Text") // <---
.AddMultipartFormDataField("Field2", "10") // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();

View File

@@ -0,0 +1,13 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();

View File

@@ -0,0 +1,10 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Data = New Structure("Field1,Field2", "10", "Text");
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetFormBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();

View File

@@ -0,0 +1,15 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
RandomArray = New Array;
RandomArray.Add("A");
RandomArray.Add("B");
RandomArray.Add("C");
Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetJsonBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();

View File

@@ -0,0 +1,12 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Text = "Hello world!";
Encoding = "Windows-1251";
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.UseEncoding(Encoding)
.SetStringBody(Text) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();

View File

@@ -0,0 +1,13 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody() // <---
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();

View File

@@ -0,0 +1,4 @@
{
"URL": "https://httpbin.org",
"Картинка": "https://api.athenaeum.digital/test_data/picture.jpg"
}

View File

@@ -0,0 +1,4 @@
{
"URL": "https://httpbin.org",
"Картинка": "https://api.athenaeum.digital/test_data/picture.jpg"
}

View File

@@ -0,0 +1,4 @@
{
"URL": "https://httpbin.org",
"Картинка": "https://api.athenaeum.digital/test_data/picture.jpg"
}

View File

@@ -0,0 +1,3 @@
{
"URL": "https://httpbin.org"
}

View File

@@ -0,0 +1,3 @@
{
"URL": "https://httpbin.org"
}

View File

@@ -0,0 +1,3 @@
{
"URL": "https://httpbin.org"
}

View File

@@ -0,0 +1,13 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Картинка = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Путь или Двоичные данные
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
.Инициализировать(URL)
.НачатьЗаписьТелаMultipart()
.ДобавитьФайлMultipartFormData("file1", "pic.png", Картинка, "image/png")
.ДобавитьПолеMultipartFormData("Поле1", "Текст") // <---
.ДобавитьПолеMultipartFormData("Поле2", "10") // <---
.ОбработатьЗапрос("POST")
.ВернутьОтветКакJSONКоллекцию();

View File

@@ -0,0 +1,13 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Картинка = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Путь или Двоичные данные
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
.Инициализировать(URL)
.НачатьЗаписьТелаMultipart()
.ДобавитьФайлMultipartFormData("file1", "pic.png", Картинка, "image/png") // <---
.ДобавитьПолеMultipartFormData("Поле1", "Текст")
.ДобавитьПолеMultipartFormData("Поле2", "10")
.ОбработатьЗапрос("POST")
.ВернутьОтветКакJSONКоллекцию();

View File

@@ -0,0 +1,13 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Картинка = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Путь или Двоичные данные
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
.Инициализировать(URL)
.НачатьЗаписьТелаMultipart() // <---
.ДобавитьФайлMultipartFormData("file1", "pic.png", Картинка, "image/png")
.ДобавитьПолеMultipartFormData("Поле1", "Текст")
.ДобавитьПолеMultipartFormData("Поле2", "10")
.ОбработатьЗапрос("POST")
.ВернутьОтветКакJSONКоллекцию();

View File

@@ -0,0 +1,10 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Данные = Новый Структура("Поле1,Поле2", "10", "Текст");
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
.Инициализировать(URL)
.УстановитьFormТело(Данные) // <---
.ОбработатьЗапрос("POST")
.ВернутьОтветКакJSONКоллекцию();

View File

@@ -0,0 +1,15 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
СлучайныйМассив = Новый Массив;
СлучайныйМассив.Добавить("A");
СлучайныйМассив.Добавить("B");
СлучайныйМассив.Добавить("C");
Данные = Новый Структура("Поле1,Поле2,Поле3", 10, "Текст", СлучайныйМассив);
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
.Инициализировать(URL)
.УстановитьJsonТело(Данные) // <---
.ОбработатьЗапрос("POST")
.ВернутьОтветКакJSONКоллекцию();

View File

@@ -0,0 +1,12 @@
 URL = "https://httpbin.org";
URL = URL + "/post";
Текст = "Привет мир!";
Кодировка = "Windows-1251";
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
.Инициализировать(URL)
.ИспользоватьКодировку(Кодировка)
.УстановитьСтроковоеТело(Текст) // <---
.ОбработатьЗапрос("POST")
.ВернутьОтветКакJSONКоллекцию();

File diff suppressed because it is too large Load Diff

View File

@@ -2643,6 +2643,12 @@ Procedure HTTP_BodySet() Export
OPI_TestDataRetrieval.ParameterToCollection("Picture" , TestParameters);
HTTPClient_SetBinaryBody(TestParameters);
HTTPClient_SetStringBody(TestParameters);
HTTPClient_SetJsonBody(TestParameters);
HTTPClient_SetFormBody(TestParameters);
HTTPClient_StartMultipartBody(TestParameters);
HTTPClient_AddMultipartFormDataField(TestParameters);
HTTPClient_AddMultipartFormDataFile(TestParameters);
EndProcedure
@@ -21072,7 +21078,11 @@ Procedure HTTPClient_Initialize(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
Try
@@ -21130,7 +21140,11 @@ Procedure HTTPClient_SetURL(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
Try
@@ -21184,7 +21198,11 @@ Procedure HTTPClient_SetURLParams(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
Address = "/get?param1=text&param2=10";
@@ -21400,7 +21418,11 @@ Procedure HTTPClient_SetDataType(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetDataType", "HTTPClient");
@@ -21448,7 +21470,11 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
Result["data"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetBinaryBody", "HTTPClient");
@@ -21462,6 +21488,265 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
EndProcedure
Procedure HTTPClient_SetStringBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Text = "Hello world!";
Encoding = "Windows-1251";
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.UseEncoding(Encoding)
.SetStringBody(Text) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/plain; charset=" + Encoding);
TextBD = ПолучитьДвоичныеДанныеИзСтроки(Text, Encoding);
Size = TextBD.Size();
OPI_TypeConversion.GetLine(Size);
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Length"]).Равно(Size);
TextB64 = "data:application/octet-stream;base64," + Base64String(TextBD);
OPI_TestDataRetrieval.ExpectsThat(Result["data"]).Равно(TextB64);
EndProcedure
Procedure HTTPClient_SetJsonBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
RandomArray = New Array;
RandomArray.Add("A");
RandomArray.Add("B");
RandomArray.Add("C");
Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetJsonBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/json; charset=utf-8");
JSONResult = Result["json"];
JSONOriginal = Data;
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field1"]).Равно(JSONOriginal["Field1"]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field2"]).Равно(JSONOriginal["Field2"]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][0]).Равно(JSONOriginal["Field3"][0]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][1]).Равно(JSONOriginal["Field3"][1]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][2]).Равно(JSONOriginal["Field3"][2]);
EndProcedure
Procedure HTTPClient_SetFormBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Data = New Structure("Field1,Field2", "10", "Text");
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetFormBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetFormBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/x-www-form-urlencoded; charset=utf-8");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно(Data["Field1"]);
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно(Data["Field2"]);
EndProcedure
Procedure HTTPClient_StartMultipartBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody() // <---
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
ResponseFile = Result["files"]["file1"];
Result["files"]["file1"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "StartMultipartBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
OPI_TypeConversion.GetBinaryData(Image);
TextB64 = "data:image/png;base64," + Base64String(Image);
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
EndProcedure
Procedure HTTPClient_AddMultipartFormDataFile(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
ResponseFile = Result["files"]["file1"];
Result["files"]["file1"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataFile", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
OPI_TypeConversion.GetBinaryData(Image);
TextB64 = "data:image/png;base64," + Base64String(Image);
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
EndProcedure
Procedure HTTPClient_AddMultipartFormDataField(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
.AddMultipartFormDataField("Field1", "Text") // <---
.AddMultipartFormDataField("Field2", "10") // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
ResponseFile = Result["files"]["file1"];
Result["files"]["file1"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataField", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
OPI_TypeConversion.GetBinaryData(Image);
TextB64 = "data:image/png;base64," + Base64String(Image);
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
EndProcedure
#EndRegion
#EndRegion

View File

@@ -294,6 +294,48 @@ EndFunction
#EndRegion
#Region Settings
Function UseEncoding(Val Encoding) Export
Try
If StopExecution() Then Return ЭтотОбъект EndIf;
AddLog("UseEncoding: Setting the value");
OPI_TypeConversion.GetLine(Encoding);
SetSetting("EncodeRequestBody", Encoding);
Return ЭтотОбъект;
Except
Return Error(DetailErrorDescription(ErrorInfo()));
EndTry;
EndFunction
Function UseGzipCompression(Val Flag) Export
Try
If StopExecution() Then Return ЭтотОбъект EndIf;
AddLog("UseGzipCompression: Setting the value");
OPI_TypeConversion.GetBoolean(Flag);
SetSetting("gzip", Flag);
Return ЭтотОбъект;
Except
Return Error(DetailErrorDescription(ErrorInfo()));
EndTry;
EndFunction
#EndRegion
#Region BodySet
// Set binary body !NOCLI
@@ -350,12 +392,11 @@ EndFunction
//
// Parameters:
// Data - String - Request body data - data
// Encoding - String - String encoding - enc
// WriteBOM - Boolean - True > BOM will be added - bom
//
// Returns:
// DataProcessorObject.OPI_HTTPClient - This processor object
Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) Export
Function SetStringBody(Val Data, Val WriteBOM = False) Export
Try
@@ -368,12 +409,16 @@ Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) E
Return ЭтотОбъект;
EndIf;
Encoding = GetSetting("EncodeRequestBody");
OPI_TypeConversion.GetLine(Encoding);
If Not RequestTypeSetManualy Then
RequestDataType = "text/plain; charset=utf-8";
RequestDataType = StrTemplate("text/plain; charset=%1", Encoding);
EndIf;
AddLog("SetStringBody: Beginning of body setting");
SetBodyFromString(Data, Encoding, WriteBOM);
SetBodyFromString(Data, WriteBOM);
AddLog(StrTemplate("SetStringBody: Body set, size %1", RequestBody.Size()));
Return ЭтотОбъект;
@@ -500,7 +545,8 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
Multipart = True;
Boundary = StrReplace(String(New UUID), "-", "");
LineSeparator = Chars.CR + Chars.LF;
RequestDataType = StrTemplate("multipart/%1; boundary=%2", View, Boundary);
Encoding = GetSetting("EncodeRequestBody");
RequestDataType = StrTemplate("multipart/%1; boundary=%2; charset=%3", View, Boundary, Encoding);
If UseFile Then
@@ -509,7 +555,7 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
RequestBodyFile = GetTempFileName();
BodyTemporaryFile = True;
RequestDataWriter = New DataWriter(RequestBodyFile
, TextEncoding.UTF8
, Encoding
, ByteOrder.LittleEndian
, ""
, False
@@ -523,13 +569,12 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
RequestBodyStream = New MemoryStream();
RequestDataWriter = New DataWriter(RequestBodyStream
, TextEncoding.UTF8
, Encoding
, ByteOrder.LittleEndian
, ""
, ""
, False);
EndIf;
Return ЭтотОбъект;
@@ -1090,7 +1135,7 @@ Function ConvertParameterToString(Val Value)
OPI_TypeConversion.GetLine(Value);
If EncodeURL Then
Value = EncodeString(Value, StringEncodingMethod.URLInURLEncoding);
Value = EncodeString(Value, StringEncodingMethod.URLencoding);
EndIf;
EndIf;
@@ -1108,9 +1153,10 @@ Function SetBodyFromBinary(Val Value)
EndFunction
Function SetBodyFromString(Val Value, Val Encoding = "UTF-8", Val WriteBOM = False)
Function SetBodyFromString(Val Value, Val WriteBOM = False)
Encoding = GetSetting("EncodeRequestBody");
OPI_TypeConversion.GetLine(Encoding);
OPI_TypeConversion.GetLine(Value);
OPI_TypeConversion.GetBoolean(WriteBOM);
@@ -1423,12 +1469,21 @@ EndFunction
Function GetResponseBody()
GZip = "gzip";
NeedsUnpacking = False;
Header1 = Response.Headers.Get("Content-Encoding");
Header2 = Response.Headers.Get("content-encoding");
For Each ResponseHeader In Response.Headers Do
NeedsUnpacking = Header1 = GZip Or Header2 = GZip;
HeaderKey = ResponseHeader.Key;
HeaderValue = ResponseHeader.Value;
If Lower(HeaderKey) = "content-encoding" Then
If Lower(HeaderValue) = "gzip" Then
NeedsUnpacking = True;
Break;
EndIf;
EndIf;
EndDo;
If NeedsUnpacking Then
Data = UnpackResponse(Response);
@@ -2121,12 +2176,17 @@ Function GetSetting(Val SettingKey)
Return Settings[SettingKey];
EndFunction
Procedure SetSetting(Val SettingKey, Val Value)
Settings[SettingKey] = Value;
EndProcedure
Procedure SetDefaultSettings()
Settings = New Structure;
Settings.Insert("gzip" , True);
Settings.Insert("SplitArrayParams" , False);
Settings.Insert("URLencoding" , True);
Settings.Insert("EncodeRequestBody" , "UTF-8");
EndProcedure

View File

@@ -2643,6 +2643,12 @@ Procedure HTTP_BodySet() Export
OPI_TestDataRetrieval.ParameterToCollection("Picture" , TestParameters);
HTTPClient_SetBinaryBody(TestParameters);
HTTPClient_SetStringBody(TestParameters);
HTTPClient_SetJsonBody(TestParameters);
HTTPClient_SetFormBody(TestParameters);
HTTPClient_StartMultipartBody(TestParameters);
HTTPClient_AddMultipartFormDataField(TestParameters);
HTTPClient_AddMultipartFormDataFile(TestParameters);
EndProcedure
@@ -21072,7 +21078,11 @@ Procedure HTTPClient_Initialize(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
Try
@@ -21130,7 +21140,11 @@ Procedure HTTPClient_SetURL(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
Try
@@ -21184,7 +21198,11 @@ Procedure HTTPClient_SetURLParams(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
Address = "/get?param1=text&param2=10";
@@ -21400,7 +21418,11 @@ Procedure HTTPClient_SetDataType(FunctionParameters)
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetDataType", "HTTPClient");
@@ -21448,7 +21470,11 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
Result["data"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetBinaryBody", "HTTPClient");
@@ -21462,6 +21488,265 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
EndProcedure
Procedure HTTPClient_SetStringBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Text = "Hello world!";
Encoding = "Windows-1251";
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.UseEncoding(Encoding)
.SetStringBody(Text) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/plain; charset=" + Encoding);
TextBD = GetBinaryDataFromString(Text, Encoding);
Size = TextBD.Size();
OPI_TypeConversion.GetLine(Size);
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Length"]).Равно(Size);
TextB64 = "data:application/octet-stream;base64," + Base64String(TextBD);
OPI_TestDataRetrieval.ExpectsThat(Result["data"]).Равно(TextB64);
EndProcedure
Procedure HTTPClient_SetJsonBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
RandomArray = New Array;
RandomArray.Add("A");
RandomArray.Add("B");
RandomArray.Add("C");
Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetJsonBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/json; charset=utf-8");
JSONResult = Result["json"];
JSONOriginal = Data;
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field1"]).Равно(JSONOriginal["Field1"]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field2"]).Равно(JSONOriginal["Field2"]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][0]).Равно(JSONOriginal["Field3"][0]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][1]).Равно(JSONOriginal["Field3"][1]);
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][2]).Равно(JSONOriginal["Field3"][2]);
EndProcedure
Procedure HTTPClient_SetFormBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Data = New Structure("Field1,Field2", "10", "Text");
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.SetFormBody(Data) // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "SetFormBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/x-www-form-urlencoded; charset=utf-8");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно(Data["Field1"]);
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно(Data["Field2"]);
EndProcedure
Procedure HTTPClient_StartMultipartBody(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody() // <---
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
ResponseFile = Result["files"]["file1"];
Result["files"]["file1"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "StartMultipartBody", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
OPI_TypeConversion.GetBinaryData(Image);
TextB64 = "data:image/png;base64," + Base64String(Image);
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
EndProcedure
Procedure HTTPClient_AddMultipartFormDataFile(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
ResponseFile = Result["files"]["file1"];
Result["files"]["file1"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataFile", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
OPI_TypeConversion.GetBinaryData(Image);
TextB64 = "data:image/png;base64," + Base64String(Image);
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
EndProcedure
Procedure HTTPClient_AddMultipartFormDataField(FunctionParameters)
URL = FunctionParameters["HTTP_URL"];
URL = URL + "/post";
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
.AddMultipartFormDataField("Field1", "Text") // <---
.AddMultipartFormDataField("Field2", "10") // <---
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
// END
Try
Result["origin"] = "***";
ResponseFile = Result["files"]["file1"];
Result["files"]["file1"] = "...";
Except
Message("Cant replace origin");
Try
Message(Result.GetLog(True));
Except
Message(GetStringFromBinaryData(Result));
EndTry;
EndTry;
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataField", "HTTPClient");
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
OPI_TypeConversion.GetBinaryData(Image);
TextB64 = "data:image/png;base64," + Base64String(Image);
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
EndProcedure
#EndRegion
#EndRegion

View File

@@ -294,6 +294,48 @@ EndFunction
#EndRegion
#Region Settings
Function UseEncoding(Val Encoding) Export
Try
If StopExecution() Then Return ThisObject EndIf;
AddLog("UseEncoding: Setting the value");
OPI_TypeConversion.GetLine(Encoding);
SetSetting("EncodeRequestBody", Encoding);
Return ThisObject;
Except
Return Error(DetailErrorDescription(ErrorInfo()));
EndTry;
EndFunction
Function UseGzipCompression(Val Flag) Export
Try
If StopExecution() Then Return ThisObject EndIf;
AddLog("UseGzipCompression: Setting the value");
OPI_TypeConversion.GetBoolean(Flag);
SetSetting("gzip", Flag);
Return ThisObject;
Except
Return Error(DetailErrorDescription(ErrorInfo()));
EndTry;
EndFunction
#EndRegion
#Region BodySet
// Set binary body !NOCLI
@@ -350,12 +392,11 @@ EndFunction
//
// Parameters:
// Data - String - Request body data - data
// Encoding - String - String encoding - enc
// WriteBOM - Boolean - True > BOM will be added - bom
//
// Returns:
// DataProcessorObject.OPI_HTTPClient - This processor object
Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) Export
Function SetStringBody(Val Data, Val WriteBOM = False) Export
Try
@@ -368,12 +409,16 @@ Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) E
Return ThisObject;
EndIf;
Encoding = GetSetting("EncodeRequestBody");
OPI_TypeConversion.GetLine(Encoding);
If Not RequestTypeSetManualy Then
RequestDataType = "text/plain; charset=utf-8";
RequestDataType = StrTemplate("text/plain; charset=%1", Encoding);
EndIf;
AddLog("SetStringBody: Beginning of body setting");
SetBodyFromString(Data, Encoding, WriteBOM);
SetBodyFromString(Data, WriteBOM);
AddLog(StrTemplate("SetStringBody: Body set, size %1", RequestBody.Size()));
Return ThisObject;
@@ -500,7 +545,8 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
Multipart = True;
Boundary = StrReplace(String(New UUID), "-", "");
LineSeparator = Chars.CR + Chars.LF;
RequestDataType = StrTemplate("multipart/%1; boundary=%2", View, Boundary);
Encoding = GetSetting("EncodeRequestBody");
RequestDataType = StrTemplate("multipart/%1; boundary=%2; charset=%3", View, Boundary, Encoding);
If UseFile Then
@@ -509,7 +555,7 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
RequestBodyFile = GetTempFileName();
BodyTemporaryFile = True;
RequestDataWriter = New DataWriter(RequestBodyFile
, TextEncoding.UTF8
, Encoding
, ByteOrder.LittleEndian
, ""
, False
@@ -523,13 +569,12 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
RequestBodyStream = New MemoryStream();
RequestDataWriter = New DataWriter(RequestBodyStream
, TextEncoding.UTF8
, Encoding
, ByteOrder.LittleEndian
, ""
, ""
, False);
EndIf;
Return ThisObject;
@@ -1090,7 +1135,7 @@ Function ConvertParameterToString(Val Value)
OPI_TypeConversion.GetLine(Value);
If EncodeURL Then
Value = EncodeString(Value, StringEncodingMethod.URLInURLEncoding);
Value = EncodeString(Value, StringEncodingMethod.URLencoding);
EndIf;
EndIf;
@@ -1108,9 +1153,10 @@ Function SetBodyFromBinaryData(Val Value)
EndFunction
Function SetBodyFromString(Val Value, Val Encoding = "UTF-8", Val WriteBOM = False)
Function SetBodyFromString(Val Value, Val WriteBOM = False)
Encoding = GetSetting("EncodeRequestBody");
OPI_TypeConversion.GetLine(Encoding);
OPI_TypeConversion.GetLine(Value);
OPI_TypeConversion.GetBoolean(WriteBOM);
@@ -1423,12 +1469,21 @@ EndFunction
Function GetResponseBody()
GZip = "gzip";
NeedsUnpacking = False;
Header1 = Response.Headers.Get("Content-Encoding");
Header2 = Response.Headers.Get("content-encoding");
For Each ResponseHeader In Response.Headers Do
NeedsUnpacking = Header1 = GZip Or Header2 = GZip;
HeaderKey = ResponseHeader.Key;
HeaderValue = ResponseHeader.Value;
If Lower(HeaderKey) = "content-encoding" Then
If Lower(HeaderValue) = "gzip" Then
NeedsUnpacking = True;
Break;
EndIf;
EndIf;
EndDo;
If NeedsUnpacking Then
Data = UnpackResponse(Response);
@@ -2121,12 +2176,17 @@ Function GetSetting(Val SettingKey)
Return Settings[SettingKey];
EndFunction
Procedure SetSetting(Val SettingKey, Val Value)
Settings[SettingKey] = Value;
EndProcedure
Procedure SetDefaultSettings()
Settings = New Structure;
Settings.Insert("gzip" , True);
Settings.Insert("SplitArrayParams" , False);
Settings.Insert("URLencoding" , True);
Settings.Insert("EncodeRequestBody" , "UTF-8");
EndProcedure

View File

@@ -1,4 +1,4 @@
// OneScript: ./OInt/tests/Modules/internal/OPI_Тесты.os
// OneScript: ./OInt/tests/Modules/internal/OPI_Тесты.os
// MIT License

View File

@@ -1,4 +1,4 @@
// OneScript: ./OInt/tools/Modules/internal/Classes/OPI_HTTPКлиент.os
// OneScript: ./OInt/tools/Modules/internal/Classes/OPI_HTTPКлиент.os
// MIT License