Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
-- Набор сценариев для UTL_HTTP.
-- utl_http_begin_request utl_http_get_response utl_http_read_text utl_http_end_response
\! rm -f /tmp/utl_http_fixture.pid /tmp/utl_http_fixture.log
\! python3 "$PG_ABS_SRCDIR/utl_http_fixture.py" > /tmp/utl_http_fixture.log 2>&1 & echo $! > /tmp/utl_http_fixture.pid
\! for attempt in $(seq 1 50); do python3 -c "import socket; s = socket.create_connection(('127.0.0.1', 18080), 1); s.close()" >/dev/null 2>&1 && exit 0; sleep 0.1; done; echo "UTL_HTTP fixture startup failed" >&2; exit 1
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url          varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_method       varchar2 := 'GET'::varchar2;
    v_http_version varchar2 := 'HTTP/1.1'::varchar2;
    v_req_context  integer  := NULL;
    v_https_host   varchar2 := NULL;
 
    req_h          integer;
    resp_h         integer;
    res_text       varchar2;
BEGIN
    -- 1. Инициализация запроса
    req_h := utl_http_begin_request(
        v_url,
        v_method,
        v_http_version,
        v_req_context,
        v_https_host
    );
 
    -- 2. Получение дескриптора ответа
    resp_h := utl_http_get_response(req_h, false::boolean);
 
    -- 3. Чтение тела ответа
    res_text := utl_http_read_text(resp_h, 1000);
 
    -- 4. Проверка на наличие данных
    IF res_text IS NULL THEN
        RAISE EXCEPTION 'Response text is NULL';
    ELSIF res_text::text = '' THEN
        RAISE EXCEPTION 'Response text is empty';
    END IF;
 
    -- 5. Проверка на наличие непустого текстового содержимого
    IF res_text::text !~ '\S' THEN
        RAISE EXCEPTION 'Response does not contain visible text';
    END IF;
 
    -- 6. Завершение сессии ответа
    PERFORM utl_http_end_response(resp_h);
 
    -- 7. Итоговый статус
    RAISE INFO 'Verification: utl_http_read_text status [OK]';
END $$;
INFO:  Verification: utl_http_read_text status [OK]
-- utl_http_set_transfer_timeout utl_http_get_transfer_timeout utl_http_request
DO $$
DECLARE
    res_text    varchar2;
    timeout_val integer;
BEGIN
    -- 1. Настройка таймаута
    PERFORM utl_http_set_transfer_timeout(10);
 
    timeout_val := utl_http_get_transfer_timeout();
    IF timeout_val != 10 THEN
        RAISE EXCEPTION 'Failed to set timeout';
    END IF;
 
    -- 2. Выполняем запрос
    res_text := utl_http_request(
        'http://127.0.0.1:18080'::varchar2,
        NULL::varchar2,
        NULL::varchar2,
        NULL::varchar2,
        NULL::varchar2
    );
 
    -- 3. Проверка результата через приведение к text
    IF res_text IS NULL THEN
        RAISE EXCEPTION 'utl_http_request returned NULL';
    ELSIF res_text::text = '' THEN
        RAISE EXCEPTION 'utl_http_request returned empty string';
    END IF;
 
    -- 4. Итоговый статус
    RAISE INFO 'Verification: utl_http_request with transfer timeout [OK]';
END $$;
INFO:  Verification: utl_http_request with transfer timeout [OK]
-- utl_http_begin_request utl_http_get_response utl_http_read_line utl_http_end_response
DO $$
DECLARE
    -- Инициализация параметров
    v_url      varchar2 := 'http://127.0.0.1:18080'::varchar2;
    req_h      integer;
    resp_h     integer;
    line1      varchar2;
    line2      varchar2;
    t_line1    text;
    t_line2    text;
BEGIN
    -- 1. Подготовка запроса
    req_h := utl_http_begin_request(v_url, 'GET'::varchar2, 'HTTP/1.1'::varchar2, NULL, NULL);
    resp_h := utl_http_get_response(req_h, false);
 
    -- 2. Чтение первой строки
    line1 := utl_http_read_line(resp_h, true);
    t_line1 := line1::text;
 
    -- Проверка на наличие данных
    IF t_line1 IS NULL OR t_line1 = '' THEN
        RAISE EXCEPTION 'Verification failed: Line 1 is empty';
    END IF;
 
    -- Проверка на отсутствие CR/LF
    IF t_line1 ~ '[\r\n]' THEN
        RAISE EXCEPTION 'Verification failed: CRLF found in Line 1';
    END IF;
 
    -- 3. Чтение второй строки
    line2 := utl_http_read_line(resp_h, true);
    t_line2 := line2::text;
 
    -- Проверка смещения указателя
    IF t_line2 IS NULL OR t_line2 = '' THEN
        RAISE EXCEPTION 'Verification failed: Line 2 is empty';
    END IF;
 
    IF t_line1 = t_line2 THEN
        RAISE EXCEPTION 'Verification failed: Line 1 and Line 2 are identical';
    END IF;
 
    -- 4. Закрытие
    PERFORM utl_http_end_response(resp_h);
 
    -- 5. Итоговый статус
    RAISE INFO 'Verification: utl_http_read_line status [OK]';
    RAISE INFO 'Verification: Pointer shift status [OK]';
    RAISE INFO 'Verification: CRLF removal status [OK]';
END $$;
INFO:  Verification: utl_http_read_line status [OK]
INFO:  Verification: Pointer shift status [OK]
INFO:  Verification: CRLF removal status [OK]
-- utl_http_begin_request utl_http_get_response utl_http_read_raw utl_http_end_response
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url          varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_method       varchar2 := 'GET'::varchar2;
    v_http_version varchar2 := 'HTTP/1.1'::varchar2;
    v_read_len     integer  := 10;
 
    req_h          integer;
    resp_h         integer;
    res_raw        raw;
BEGIN
    -- 1. Инициализация сетевого запроса
    req_h := utl_http_begin_request(
        v_url,
        v_method,
        v_http_version,
        NULL::integer,
        NULL::varchar2
    );
 
    -- 2. Получение дескриптора ответа
    resp_h := utl_http_get_response(req_h, false::boolean);
 
    -- 3. Чтение данных методом utl_http_read_raw
    res_raw := utl_http_read_raw(resp_h, v_read_len);
 
    -- 4. Валидация результата
    IF res_raw IS NULL THEN
        RAISE EXCEPTION 'utl_http_read_raw returned NULL';
    END IF;
 
    IF length(res_raw::text) = 0 THEN
        RAISE EXCEPTION 'Verification failed: utl_http_read_raw returned empty data';
    END IF;
 
    -- 5. Завершение работы с ответом
    PERFORM utl_http_end_response(resp_h);
 
    -- 6. Итоговый статус
    RAISE INFO 'Verification: utl_http_read_raw execution success';
    RAISE INFO 'Verification: utl_http_end_response execution success';
END $$;
INFO:  Verification: utl_http_read_raw execution success
INFO:  Verification: utl_http_end_response execution success
-- utl_http_set_transfer_timeout utl_http_set_response_error_check utl_http_request
-- Влияние настроек таймаута и проверки ошибок на utl_http_request
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url          varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_timeout      integer  := 15;
    v_error_check  boolean  := true;
 
    res_text       varchar2;
BEGIN
    -- 1. Установка глобальных настроек сессии
    PERFORM utl_http_set_transfer_timeout(v_timeout);
    PERFORM utl_http_set_response_error_check(v_error_check);
 
    -- 2. Выполнение автономного запроса
    res_text := utl_http_request(
        v_url,
        NULL::varchar2,
        NULL::varchar2,
        NULL::varchar2,
        NULL::varchar2
    );
 
    -- 3. Валидация результата
    IF res_text IS NULL THEN
        RAISE EXCEPTION 'Verification failed: utl_http_request returned NULL';
    ELSIF res_text::text = '' THEN
        RAISE EXCEPTION 'Verification failed: utl_http_request returned empty string';
    END IF;
 
    -- 4. Итоговый статус
    RAISE INFO 'Verification: utl_http_request with timeout/error_check settings [OK]';
END $$;
INFO:  Verification: utl_http_request with timeout/error_check settings [OK]
-- utl_http_set_follow_redirect_session utl_http_set_body_charset_session utl_http_request
-- Влияние настроек переадресации и кодировки на utl_http_request
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url          varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_max_redirs   integer  := 5;
    v_charset      varchar2 := 'UTF-8'::varchar2;
 
    res_text       varchar2;
BEGIN
    -- 1. Установка глобальных настроек переадресации и кодировки
    PERFORM utl_http_set_follow_redirect_session(v_max_redirs);
    PERFORM utl_http_set_body_charset_session(v_charset);
 
    -- 2. Выполнение автономного запроса
    res_text := utl_http_request(
        v_url,
        NULL::varchar2,
        NULL::varchar2,
        NULL::varchar2,
        NULL::varchar2
    );
 
    -- 3. Валидация результата
    IF res_text IS NULL THEN
        RAISE EXCEPTION 'Verification failed: response is null';
    ELSIF res_text::text = '' THEN
        RAISE EXCEPTION 'Verification failed: response is empty';
    END IF;
 
    -- 4. Итоговый статус
    RAISE INFO 'Verification: utl_http_request with redirect/charset settings [OK]';
    RAISE INFO 'Verification: Autonomous request execution status [SUCCESS]';
END $$;
INFO:  Verification: utl_http_request with redirect/charset settings [OK]
INFO:  Verification: Autonomous request execution status [SUCCESS]
-- Группа 1: Глобальные настройки сессии (Конфигурация)
-- Эти методы удобно проверять парами установки и чтения.
-- utl_http_set_transfer_timeout + utl_http_get_transfer_timeout
-- utl_http_set_follow_redirect_session + utl_http_get_follow_redirect
-- utl_http_set_response_error_check + utl_http_get_response_error_check
-- utl_http_set_body_charset_session + utl_http_get_body_charset
-- utl_http_set_proxy + utl_http_get_proxy
DO $$
DECLARE
    -- Инициализация тестовых значений
    v_timeout_in   integer  := 45;
    v_timeout_out  integer;
 
    v_redir_in     integer  := 7;
    v_redir_out    integer;
 
    v_err_check_in boolean  := true;
    v_err_check_out boolean;
 
    v_charset_in   varchar2 := 'windows-1251'::varchar2;
    v_charset_out  varchar2;
 
    v_proxy_in     varchar2 := 'http://proxy.test:8080'::varchar2;
    v_no_proxy_in  varchar2 := 'localhost,127.0.0.1'::varchar2;
    v_proxy_out    varchar2;
    v_no_proxy_out varchar2;
BEGIN
    -- 1. Тест Transfer Timeout
    PERFORM utl_http_set_transfer_timeout(v_timeout_in);
    v_timeout_out := utl_http_get_transfer_timeout();
    IF v_timeout_out != v_timeout_in THEN
        RAISE EXCEPTION 'Verification failed: transfer_timeout mismatch';
    END IF;
 
    -- 2. Тест Follow Redirect
    PERFORM utl_http_set_follow_redirect_session(v_redir_in);
    v_redir_out := utl_http_get_follow_redirect();
    IF v_redir_out != v_redir_in THEN
        RAISE EXCEPTION 'Verification failed: follow_redirect mismatch';
    END IF;
 
    -- 3. Тест Response Error Check
    PERFORM utl_http_set_response_error_check(v_err_check_in);
    v_err_check_out := utl_http_get_response_error_check();
    IF v_err_check_out != v_err_check_in THEN
        RAISE EXCEPTION 'Verification failed: response_error_check mismatch';
    END IF;
 
    -- 4. Тест Body Charset
    PERFORM utl_http_set_body_charset_session(v_charset_in);
    v_charset_out := utl_http_get_body_charset();
    IF v_charset_out::text <> v_charset_in::text THEN
        RAISE EXCEPTION 'Verification failed: body_charset mismatch';
    END IF;
 
    -- 5. Тест Proxy
    PERFORM utl_http_set_proxy(v_proxy_in, v_no_proxy_in);
    SELECT proxy, no_proxy_domains INTO v_proxy_out, v_no_proxy_out FROM utl_http_get_proxy();
    IF v_proxy_out::text <> v_proxy_in::text OR v_no_proxy_out::text <> v_no_proxy_in::text THEN
        RAISE EXCEPTION 'Verification failed: proxy settings mismatch';
    END IF;
 
    -- Итоговое подтверждение
    RAISE INFO 'Verification: Group 1 Configuration Status [SUCCESS]';
END $$;
INFO:  Verification: Group 1 Configuration Status [SUCCESS]
-- Группа 2: Жизненный цикл запроса и инспекция метаданных
-- utl_http_set_proxy
-- utl_http_begin_request
-- utl_http_set_header
-- utl_http_get_response
-- utl_http_get_header_count
-- utl_http_get_header
-- utl_http_get_header_by_name
-- utl_http_end_response
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url            varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_ua_name        varchar2 := 'User-Agent'::varchar2;
    v_ua_val         varchar2 := 'RUDB-Tester/1.0'::varchar2;
 
    req_h            integer;
    resp_h           integer;
    v_h_count        integer;
    v_h_name         varchar2;
    v_h_val          varchar2;
    v_content_type   varchar2;
BEGIN
    -- 0. Сброс состояния
    PERFORM utl_http_set_proxy(NULL::varchar2, NULL::varchar2);
 
    -- 1. Инициализация
    req_h := utl_http_begin_request(
        v_url,
        'GET'::varchar2,
        'HTTP/1.1'::varchar2,
        NULL::integer,
        NULL::varchar2
    );
 
    -- 2. Установка заголовка клиента
    PERFORM utl_http_set_header(req_h, v_ua_name, v_ua_val);
 
    -- 3. Фиксация запроса и получение ответа
    resp_h := utl_http_get_response(req_h, false::boolean);
 
    -- 4. Инспекция заголовков сервера
    v_h_count := utl_http_get_header_count(resp_h);
    IF v_h_count IS NULL OR v_h_count <= 0 THEN
        RAISE EXCEPTION 'Verification failed: server returned 0 headers';
    END IF;
 
    SELECT name, value INTO v_h_name, v_h_val FROM utl_http_get_header(resp_h, 1);
    IF v_h_name IS NULL OR v_h_name::text = '' THEN
        RAISE EXCEPTION 'Verification failed: first header is null or empty';
    END IF;
 
    v_content_type := utl_http_get_header_by_name(resp_h, 'Content-Type'::varchar2, 1);
    IF v_content_type IS NULL OR v_content_type::text = '' THEN
        RAISE EXCEPTION 'Verification failed: Content-Type header not found';
    END IF;
 
    -- 5. Проверка структуры значения заголовка
    IF position('/' in v_content_type::text) = 0 THEN
        RAISE EXCEPTION 'Verification failed: unexpected Content-Type format';
    END IF;
 
    -- 6. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    RAISE INFO 'Verification: Request lifecycle and Proxy reset [OK]';
    RAISE INFO 'Verification: Headers metadata inspection [OK]';
END $$;
INFO:  Verification: Request lifecycle and Proxy reset [OK]
INFO:  Verification: Headers metadata inspection [OK]
-- Группа 3: Работа с телом запроса (Запись данных)
-- utl_http_set_proxy
-- utl_http_begin_request
-- utl_http_set_header
-- utl_http_write_text
-- utl_http_write_line
-- utl_http_write_raw
-- utl_http_get_response
-- utl_http_read_text
-- utl_http_end_response
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url          varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_method       varchar2 := 'POST'::varchar2;
    v_data_text    varchar2 := 'Simple text data'::varchar2;
    v_data_line    varchar2 := 'Line with CRLF'::varchar2;
    v_data_raw     raw      := '\x48656c6c6f'::bytea;
 
    req_h          integer;
    resp_h         integer;
    res_val        varchar2;
BEGIN
    -- 0. Сброс прокси для чистоты теста
    PERFORM utl_http_set_proxy(NULL::varchar2, NULL::varchar2);
 
    -- 1. Инициализация POST-запроса
    req_h := utl_http_begin_request(
        v_url,
        v_method,
        'HTTP/1.1'::varchar2,
        NULL::integer,
        NULL::varchar2
    );
 
    -- 2. Установка необходимых заголовков для передачи тела
    PERFORM utl_http_set_header(req_h, 'Content-Type'::varchar2, 'text/plain'::varchar2);
 
    -- 3. Тестирование методов записи
    PERFORM utl_http_write_text(req_h, v_data_text);
    PERFORM utl_http_write_line(req_h, v_data_line);
    PERFORM utl_http_write_raw(req_h, v_data_raw);
 
    -- 4. Получение ответа
    resp_h := utl_http_get_response(req_h, false::boolean);
 
    -- 5. Валидация факта получения ответа
    res_val := utl_http_read_text(resp_h, 1);
    IF res_val IS NULL THEN
        RAISE EXCEPTION 'Verification failed: No response from server after POST';
    END IF;
 
    -- 6. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    -- 7. Итоговый статус
    RAISE INFO 'Verification: utl_http_write_text execution [SUCCESS]';
    RAISE INFO 'Verification: utl_http_write_line execution [SUCCESS]';
    RAISE INFO 'Verification: utl_http_write_raw execution [SUCCESS]';
END $$;
INFO:  Verification: utl_http_write_text execution [SUCCESS]
INFO:  Verification: utl_http_write_line execution [SUCCESS]
INFO:  Verification: utl_http_write_raw execution [SUCCESS]
-- Группа 4: Управление куками.
-- Проверочный сценарий для проверки стабильности вызовов.
-- utl_http_get_cookie_count
-- utl_http_get_cookies
-- utl_http_clear_cookies
DO $$
DECLARE
    v_url           varchar2 := 'http://127.0.0.1:18080'::varchar2;
    req_h           integer;
    resp_h          integer;
    v_logic_cookies integer;
    v_cookie_rows   integer := 0;
    r_cookie        record;
BEGIN
    -- 0. Настройка
    PERFORM utl_http_set_proxy(NULL::varchar2, NULL::varchar2);
    PERFORM utl_http_set_follow_redirect_session(5);
 
    -- 1. Запрос
    req_h := utl_http_begin_request(v_url, 'GET'::varchar2, 'HTTP/1.1'::varchar2, NULL, NULL);
    resp_h := utl_http_get_response(req_h, false);
 
    -- 2. Проверка через встроенный метод
    v_logic_cookies := utl_http_get_cookie_count(NULL::integer);
    IF v_logic_cookies IS NULL THEN
        RAISE EXCEPTION 'Verification failed: utl_http_get_cookie_count returned NULL';
    END IF;
 
    -- 3. Проверка получения списка cookies
    FOR r_cookie IN
        SELECT * FROM utl_http_get_cookies(NULL::integer)
    LOOP
        v_cookie_rows := v_cookie_rows + 1;
    END LOOP;
 
    IF v_cookie_rows < 0 THEN
        RAISE EXCEPTION 'Verification failed: invalid cookie rows count';
    END IF;
 
    -- 4. Проверка очистки cookies
    PERFORM utl_http_clear_cookies(NULL::integer);
 
    -- 5. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    -- 6. Итоговый статус
    RAISE INFO 'Verification: Cookie methods smoke status [OK]';
END $$;
INFO:  Verification: Cookie methods smoke status [OK]
-- Группа 5: Безопасность и аутентификация
-- utl_http_set_proxy
-- utl_http_begin_request
-- utl_http_set_authentication
-- utl_http_get_response
-- utl_http_get_authentication
-- utl_http_end_response
--
-- Техническое замечание:
-- Метод utl_http_set_authentication_from_wallet требует предварительного вызова
-- utl_http_set_wallet. Полноценный сетевой сценарий для аутентификации
-- через хранилище учетных данных
-- в текущем файле не добавляется.
DO $$
DECLARE
    -- Инициализация параметров по умолчанию
    v_url        varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_user       varchar2 := 'test_user'::varchar2;
    v_pass       varchar2 := 'test_password'::varchar2;
    v_scheme_in  varchar2 := 'Basic'::varchar2;
 
    req_h        integer;
    resp_h       integer;
    v_sch_out    varchar2;
    v_rlm_out    varchar2;
BEGIN
    -- 0. Предварительная настройка сессии
    PERFORM utl_http_set_proxy(NULL::varchar2, NULL::varchar2);
 
    -- 1. Тест utl_http_set_authentication
    req_h := utl_http_begin_request(v_url, 'GET'::varchar2, 'HTTP/1.1'::varchar2, NULL, NULL);
 
    PERFORM utl_http_set_authentication(
        req_h,
        v_user,
        v_pass,
        v_scheme_in,
        false
    );
 
    -- 2. Фиксация запроса и получение ответа
    resp_h := utl_http_get_response(req_h, false);
 
    -- 3. Тест utl_http_get_authentication
    SELECT scheme, realm INTO v_sch_out, v_rlm_out
    FROM utl_http_get_authentication(resp_h, false);
 
    -- 4. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    -- 5. Итоговый статус
    RAISE INFO 'Verification: utl_http_set_authentication status [OK]';
    RAISE INFO 'Verification: utl_http_get_authentication status [OK]';
    RAISE INFO 'Status: Group 5 Security methods execution success';
END $$;
INFO:  Verification: utl_http_set_authentication status [OK]
INFO:  Verification: utl_http_get_authentication status [OK]
INFO:  Status: Group 5 Security methods execution success
-- Комплексный тест 1
-- utl_http_set_proxy
-- utl_http_begin_request
-- utl_http_get_response
-- utl_http_get_cookie_count
-- utl_http_end_response
DO $$
DECLARE
    req_h        integer;
    resp_h       integer;
    v_cookie_cnt integer;
BEGIN
    PERFORM utl_http_set_proxy(NULL::varchar2, NULL::varchar2);
 
    -- 1. Запрос
    req_h := utl_http_begin_request('http://127.0.0.1:18080'::varchar2, 'GET'::varchar2, 'HTTP/1.1'::varchar2, NULL, NULL);
    resp_h := utl_http_get_response(req_h, false);
 
    -- 2. Проверка cookies
    v_cookie_cnt := utl_http_get_cookie_count(NULL::integer);
    IF v_cookie_cnt IS NULL THEN
        RAISE EXCEPTION 'Strict verification failed: utl_http_get_cookie_count returned NULL';
    END IF;
 
    -- 3. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    -- 4. Итоговый статус
    RAISE INFO 'Verification: Cookie manager state [OK]';
    RAISE INFO 'Status: Complex cookie scenario execution success';
END $$;
INFO:  Verification: Cookie manager state [OK]
INFO:  Status: Complex cookie scenario execution success
-- Комплексный тест 2
-- utl_http_set_transfer_timeout
-- utl_http_get_transfer_timeout
-- utl_http_set_response_error_check
-- utl_http_get_response_error_check
-- utl_http_set_follow_redirect_session
-- utl_http_get_follow_redirect
-- utl_http_set_body_charset_session
-- utl_http_get_body_charset
-- utl_http_begin_request
-- utl_http_get_response
-- utl_http_read_text
-- utl_http_end_response
DO $$
DECLARE
    -- Параметры сессии
    v_timeout     integer  := 15;
    v_err_check   boolean  := true;
    v_redirects   integer  := 3;
    v_charset     varchar2 := 'UTF-8'::varchar2;
 
    -- Дескрипторы и переменные для данных
    req_h         integer;
    resp_h        integer;
    v_res_text    varchar2;
    v_ret_charset varchar2;
BEGIN
    -- 1. Тест глобальных настроек
    PERFORM utl_http_set_transfer_timeout(v_timeout);
    IF utl_http_get_transfer_timeout() != v_timeout THEN
        RAISE EXCEPTION 'Timeout verification failed';
    END IF;
 
    PERFORM utl_http_set_response_error_check(v_err_check);
    IF utl_http_get_response_error_check() != v_err_check THEN
        RAISE EXCEPTION 'Error check verification failed';
    END IF;
 
    PERFORM utl_http_set_follow_redirect_session(v_redirects);
    IF utl_http_get_follow_redirect() != v_redirects THEN
        RAISE EXCEPTION 'Redirects verification failed';
    END IF;
 
    PERFORM utl_http_set_body_charset_session(v_charset);
    v_ret_charset := utl_http_get_body_charset();
    IF v_ret_charset::text != v_charset::text THEN
        RAISE EXCEPTION 'Charset verification failed';
    END IF;
 
    RAISE INFO 'Verification: Session settings [OK]';
 
    -- 2. Тест запроса после настройки сессии
    req_h := utl_http_begin_request('http://127.0.0.1:18080'::varchar2, 'GET'::varchar2, 'HTTP/1.1'::varchar2, NULL, NULL);
    resp_h := utl_http_get_response(req_h, false);
    v_res_text := utl_http_read_text(resp_h, 1);
    IF v_res_text IS NULL THEN
        RAISE EXCEPTION 'Response body access verification failed';
    END IF;
 
    RAISE INFO 'Verification: Request after session settings [OK]';
 
    -- 3. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    RAISE INFO 'Status: Success chain execution';
END $$;
INFO:  Verification: Session settings [OK]
INFO:  Verification: Request after session settings [OK]
INFO:  Status: Success chain execution
-- Дополнительный детерминированный сценарий.
-- Методы:
-- utl_http_clear_cookies
-- utl_http_get_cookie_count
-- utl_http_get_cookies
DO $$
DECLARE
    v_cookie_count integer;
    v_cookie_rows  integer := 0;
    r_cookie       record;
BEGIN
    -- 1. Очистка cookie-хранилища
    PERFORM utl_http_clear_cookies(NULL::integer);
 
    -- 2. Проверка счетчика cookies
    v_cookie_count := utl_http_get_cookie_count(NULL::integer);
    IF v_cookie_count != 0 THEN
        RAISE EXCEPTION 'cookie_count after clear mismatch';
    END IF;
 
    -- 3. Проверка списка cookies
    FOR r_cookie IN
        SELECT * FROM utl_http_get_cookies(NULL::integer)
    LOOP
        v_cookie_rows := v_cookie_rows + 1;
    END LOOP;
 
    IF v_cookie_rows != 0 THEN
        RAISE EXCEPTION 'cookie rows after clear mismatch';
    END IF;
 
    -- 4. Итоговый статус
    RAISE INFO 'Verification: utl_http_clear_cookies status [OK]';
    RAISE INFO 'Verification: utl_http_get_cookies status [OK]';
END $$;
INFO:  Verification: utl_http_clear_cookies status [OK]
INFO:  Verification: utl_http_get_cookies status [OK]
-- Дополнительный детерминированный сценарий.
-- Методы:
-- utl_http_create_request_context
-- utl_http_destroy_request_context
-- utl_http_get_detailed_sqlcode
-- utl_http_get_detailed_sqlerrm
-- utl_http_get_detailed_excp_support
-- utl_http_get_detailed_excp_support_fn
DO $$
DECLARE
    v_ctx      integer;
    v_sqlcode  integer;
    v_sqlerrm  varchar2;
    v_detailed boolean;
BEGIN
    -- 1. Создание контекста запроса
    v_ctx := utl_http_create_request_context(
        NULL::varchar2,
        NULL::varchar2,
        false,
        0,
        0
    );
 
    IF v_ctx IS NULL OR v_ctx <= 0 THEN
        RAISE EXCEPTION 'request_context handle mismatch';
    END IF;
 
    -- 2. Уничтожение контекста
    PERFORM utl_http_destroy_request_context(v_ctx);
 
    -- 3. Проверка диагностических значений по умолчанию
    v_sqlcode := utl_http_get_detailed_sqlcode();
    IF v_sqlcode != 0 THEN
        RAISE EXCEPTION 'detailed_sqlcode default mismatch';
    END IF;
 
    v_sqlerrm := utl_http_get_detailed_sqlerrm();
    IF v_sqlerrm::text != '' THEN
        RAISE EXCEPTION 'detailed_sqlerrm default mismatch';
    END IF;
 
    v_detailed := utl_http_get_detailed_excp_support();
    IF v_detailed != false THEN
        RAISE EXCEPTION 'detailed_excp_support default mismatch';
    END IF;
 
    v_detailed := utl_http_get_detailed_excp_support_fn();
    IF v_detailed != false THEN
        RAISE EXCEPTION 'detailed_excp_support_fn default mismatch';
    END IF;
 
    -- 4. Итоговый статус
    RAISE INFO 'Verification: Request context lifecycle [OK]';
    RAISE INFO 'Verification: Diagnostic defaults [OK]';
END $$;
INFO:  Verification: Request context lifecycle [OK]
INFO:  Verification: Diagnostic defaults [OK]
-- Дополнительный проверочный сценарий.
-- Методы:
-- utl_http_begin_request
-- utl_http_get_response
-- utl_http_set_body_charset_resp
-- utl_http_read_text
-- utl_http_end_response
DO $$
DECLARE
    v_url      varchar2 := 'http://127.0.0.1:18080'::varchar2;
    req_h      integer;
    resp_h     integer;
    res_text   varchar2;
BEGIN
    -- 1. Инициализация и получение ответа
    req_h := utl_http_begin_request(v_url, 'GET'::varchar2, 'HTTP/1.1'::varchar2, NULL, NULL);
    resp_h := utl_http_get_response(req_h, false);
 
    -- 2. Установка кодировки тела ответа
    PERFORM utl_http_set_body_charset_resp(resp_h, 'UTF-8'::varchar2);
 
    -- 3. Проверка дальнейшего чтения ответа
    res_text := utl_http_read_text(resp_h, 1);
    IF res_text IS NULL THEN
        RAISE EXCEPTION 'Verification failed: utl_http_set_body_charset_resp smoke';
    END IF;
 
    -- 4. Завершение
    PERFORM utl_http_end_response(resp_h);
 
    -- 5. Итоговый статус
    RAISE INFO 'Verification: utl_http_set_body_charset_resp smoke [OK]';
END $$;
INFO:  Verification: utl_http_set_body_charset_resp smoke [OK]
-- Дополнительный проверочный сценарий.
-- Методы:
-- utl_http_request_pieces
DO $$
DECLARE
    v_url         varchar2 := 'http://127.0.0.1:18080'::varchar2;
    v_piece_count integer := 0;
    v_piece       record;
BEGIN
    -- 1. Выполнение запроса порциями
    FOR v_piece IN
        SELECT * FROM utl_http_request_pieces(
            v_url,
            3,
            NULL::varchar2,
            NULL::varchar2,
            NULL::varchar2,
            NULL::varchar2
        )
    LOOP
        v_piece_count := v_piece_count + 1;
    END LOOP;
 
    -- 2. Проверка результата
    IF v_piece_count <= 0 THEN
        RAISE EXCEPTION 'Verification failed: utl_http_request_pieces returned no pieces';
    END IF;
 
    -- 3. Итоговый статус
    RAISE INFO 'Verification: utl_http_request_pieces smoke [OK]';
END $$;
INFO:  Verification: utl_http_request_pieces smoke [OK]
\! test ! -f /tmp/utl_http_fixture.pid || kill "$(cat /tmp/utl_http_fixture.pid)" 2>/dev/null || true; rm -f /tmp/utl_http_fixture.pid /tmp/utl_http_fixture.log