Skip to content

Fix RAW HTTPStream#1630

Merged
EvilBeaver merged 9 commits intoEvilBeaver:developfrom
asosnoviy:fix/rawStream
Dec 13, 2025
Merged

Fix RAW HTTPStream#1630
EvilBeaver merged 9 commits intoEvilBeaver:developfrom
asosnoviy:fix/rawStream

Conversation

@asosnoviy
Copy link
Contributor

@asosnoviy asosnoviy commented Dec 12, 2025

Перенес вычитывание потока из инициализации body в получение потока.

Summary by CodeRabbit

  • New Features

    • Response bodies can be read multiple times and you can opt to open the raw underlying stream directly.
  • Bug Fixes

    • Clearer errors and safer behavior when no response body or stream is available.
  • Tests

    • Added tests covering repeated body reads, behavior after closing streams, and raw-stream access; tests now use a dynamic host selection and include an additional HTTPS host.
  • Chores

    • Minor formatting and test setup cleanups.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

Adds a raw-stream flag to response stream access, moves response initialization into in-memory vs file-backed paths, removes HttpWebResponse parameters from several internals, and extends tests to cover repeated and post-closure body reads and dynamic test hosts.

Changes

Cohort / File(s) Change Summary
HTTP response body implementation
src/OneScript.StandardLibrary/Http/HttpResponseBody.cs
Introduced _inMemoryResponseInited and shifted initialization into InitInMemoryResponse() / InitFileBackedResponse(string); changed OpenReadStream()OpenReadStream(bool raw = false) to optionally return the raw underlying stream; removed HttpWebResponse parameters from GetResponseStream(), ReadToStream(), ReadToArray() and updated internal callers; _rawStream used centrally and GZip decompression applied in GetResponseStream(); added InvalidOperationException when no body available; adjusted disposal/lifecycle handling.
HTTP response context
src/OneScript.StandardLibrary/Http/HttpResponseContext.cs
GetBodyAsStream() now accepts bool rawStream = false and forwards it to _body.OpenReadStream(rawStream); XML doc updated for the parameter.
HTTP tests and globals
tests/http.os, tests/global-funcs.os
Added tests for repeated body reads and behavior after closing streams (ТестДолженПроверитьЧтоТелоМожноПолучитьНесколькоРаз, ТестДолженПроверитьПолучениеТелаПослеЗакрытогоПотока, ТестДолженПроверитьНедоступностьЧистогоПотокаПослеПолученияТела); made host-selection function exportable and added https://connectorhttp.ru candidate; introduced global мАдресРесурса and updated test URLs to use it.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify all call sites that now pass raw to OpenReadStream(bool) and ensure callers handle raw vs processed streams correctly.
  • Inspect disposal and lifetime of _rawStream and file-backed streams, and backing-file cleanup.
  • Validate GZip decompression decisions and content-length / length-reporting behavior.
  • Review new tests for reliance on external hosts and potential flakiness.

Possibly related PRs

Poem

🐰 I nibble bytes and hop through streams,
I stash them lazy, soft as dreams.
A raw little peek, then memory snug,
Tests clap their paws, give code a hug.
Hooray — I tunneled through bytes like thrum and drums! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix RAW HTTPStream' is specific and directly relates to the main changes in the PR, which involve refactoring HTTP response stream handling with a new raw parameter.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3fe6700 and b751058.

📒 Files selected for processing (3)
  • src/OneScript.StandardLibrary/Http/HttpResponseBody.cs (6 hunks)
  • src/OneScript.StandardLibrary/Http/HttpResponseContext.cs (1 hunks)
  • tests/http.os (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (.cursor/rules/langversion.mdc)

Do not use C# language features that are not available in C# 8 when generating code for projects using .NET 8.0 with LangVersion 8

Files:

  • src/OneScript.StandardLibrary/Http/HttpResponseContext.cs
  • src/OneScript.StandardLibrary/Http/HttpResponseBody.cs
🧠 Learnings (2)
📓 Common learnings
Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2024-08-05T18:27:08.563Z
Learning: For each new pull request in the EvilBeaver/OneScript repository, include a poem in Russian.
Learnt from: sfaqer
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2025-05-23T03:00:18.462Z
Learning: User sfaqer prefers communication in Russian language.
📚 Learning: 2025-12-01T15:13:19.064Z
Learnt from: CR
Repo: EvilBeaver/OneScript PR: 0
File: .cursor/rules/runbsltests.mdc:0-0
Timestamp: 2025-12-01T15:13:19.064Z
Learning: Ignore errors from http.os test file and the test named 'Тест_ДолженПроверитьЧтоПеремещениеФайлаРаботаетПоHTTP' when reviewing BSL test results

Applied to files:

  • tests/http.os
🧬 Code graph analysis (1)
src/OneScript.StandardLibrary/Http/HttpResponseContext.cs (1)
src/OneScript.StandardLibrary/Binary/GenericStream.cs (2)
  • GenericStream (37-42)
  • GenericStream (44-49)
🔇 Additional comments (7)
src/OneScript.StandardLibrary/Http/HttpResponseContext.cs (1)

164-164: Correct usage of the new raw stream mode.

The change to pass true to OpenReadStream(true) appropriately enables raw stream access, allowing the underlying HTTP response stream to be returned without buffering. This aligns with the refactoring objective to move stream consumption from initialization to retrieval time.

tests/http.os (1)

396-418: Comprehensive test for the new lazy initialization behavior.

This test effectively validates the refactored body retrieval logic:

  • Multiple raw stream retrievals before actual consumption (lines 405-407)
  • Transition to buffered mode via GetBodyAsBinaryData() (line 409)
  • Repeated buffered retrievals after initialization (lines 410-414, 416)

The test confirms that the lazy initialization pattern works correctly for both streaming and buffered scenarios.

src/OneScript.StandardLibrary/Http/HttpResponseBody.cs (5)

26-29: Good use of readonly modifiers and initialization tracking.

The addition of readonly modifiers for _autoDecompress and _rawStream improves immutability, and the _inMemoryResponseInited flag properly tracks the lazy initialization state for the new pattern.


31-52: Lazy initialization pattern successfully implemented in constructor.

The refactored constructor now defers stream consumption in most cases:

  • Stores _rawStream for later use (line 40)
  • Immediately initializes only for file-backed (line 46) or auto-decompress scenarios (line 50)
  • Otherwise leaves stream unconsumed for raw streaming access

This change enables efficient streaming scenarios like Server-Sent Events where buffering the entire response is unnecessary.


104-109: Clean refactoring of GetResponseStream().

Removing the HttpWebResponse parameter and operating on the internal _rawStream field simplifies the method signature and makes the lazy initialization pattern more cohesive.


111-194: Consistent refactoring of internal read methods.

The removal of HttpWebResponse parameters from ReadToStream(), ReadToArray(), and InitFileBackedResponse() maintains consistency with the lazy initialization design. All methods now appropriately rely on internal state via GetResponseStream().


166-166: C# 8 using var declaration is appropriate.

The using var statement at line 166 is compatible with C# 8, which aligns with the project's language version requirements per the coding guidelines.

Comment on lines +80 to 102
public Stream OpenReadStream(bool raw = false)
{
if (raw && !_inMemoryResponseInited)
{
return GetResponseStream();
}

if (!_inMemoryResponseInited)
{
InitInMemoryResponse();
}

if (_backingFileName != null)
{
return new FileStream(_backingFileName, FileMode.Open, FileAccess.Read);
}
else if (_inMemBody != null)
{
return new MemoryStream(_inMemBody);
}
else if (_inMemBody != null)
{
return new MemoryStream(_inMemBody);
}
else
return _rawStream;
throw new InvalidOperationException("No response body");
}
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 12, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n src/OneScript.StandardLibrary/Http/HttpResponseBody.cs | head -120

Repository: EvilBeaver/OneScript

Length of output: 4589


🏁 Script executed:

# Search for _inMemoryResponseInited usage and thread safety patterns
rg -n "_inMemoryResponseInited" src/OneScript.StandardLibrary/Http/HttpResponseBody.cs -A2 -B2

Repository: EvilBeaver/OneScript

Length of output: 954


🏁 Script executed:

# Check for lock statements, volatile keywords, or thread safety attributes in the file
rg -n "(lock|volatile|ThreadSafe|Thread\.|Monitor\.|Interlocked\.|async|Task\.Run)" src/OneScript.StandardLibrary/Http/HttpResponseBody.cs

Repository: EvilBeaver/OneScript

Length of output: 46


🏁 Script executed:

# Check if HttpResponseBody is used in concurrent scenarios in tests or other code
rg -n "HttpResponseBody" --type=cs | head -20

Repository: EvilBeaver/OneScript

Length of output: 610


🏁 Script executed:

# Look for usage patterns that might indicate concurrent access
rg -n -B5 -A5 "HttpResponseBody" src/OneScript.StandardLibrary/Http/ --type=cs

Repository: EvilBeaver/OneScript

Length of output: 4955


🏁 Script executed:

# Check for async/Task usage patterns that might indicate concurrent access
rg -l "(async|await|Task|Thread\.Start|Parallel|lock)" src/OneScript.StandardLibrary/ --type=cs | head -10

Repository: EvilBeaver/OneScript

Length of output: 669


🏁 Script executed:

# Check if HttpResponseContext is used in async contexts
rg -n -B3 -A3 "HttpResponseContext" src/OneScript.StandardLibrary/ --type=cs | head -40

Repository: EvilBeaver/OneScript

Length of output: 3958


🏁 Script executed:

# Look for any documentation or comments about thread safety
rg -n "(thread|concurrent|async|parallel)" src/OneScript.StandardLibrary/Http/ --type=cs -i

Repository: EvilBeaver/OneScript

Length of output: 196


🏁 Script executed:

# Check the full Dispose pattern to understand lifecycle
cat -n src/OneScript.StandardLibrary/Http/HttpResponseBody.cs | tail -20

Repository: EvilBeaver/OneScript

Length of output: 540


🏁 Script executed:

# Search for any test files that might show usage patterns
fd -e "test.cs" -e "Tests.cs" | xargs rg -l "HttpResponse" 2>/dev/null | head -5

Repository: EvilBeaver/OneScript

Length of output: 304


🏁 Script executed:

# Check if this is a script engine and look for threading models
fd "Program.cs\|Main.cs\|Engine" --type f | head -10

Repository: EvilBeaver/OneScript

Length of output: 46


🏁 Script executed:

# Check BackgroundTask implementation
rg -n "class BackgroundTask" src/OneScript.StandardLibrary/Tasks/ -A 20

Repository: EvilBeaver/OneScript

Length of output: 4450


🏁 Script executed:

# Check if HttpResponseContext could be shared across tasks
rg -n "HttpResponseContext\|HttpResponseBody" src/OneScript.StandardLibrary/Tasks/ -A 3 -B 3

Repository: EvilBeaver/OneScript

Length of output: 46


🏁 Script executed:

# Look for any documentation or comments about thread-safety in the HTTP module
rg -n "thread|concurrent|safe|race" src/OneScript.StandardLibrary/Http/ --type=cs -i

Repository: EvilBeaver/OneScript

Length of output: 323


🏁 Script executed:

# Check if the raw parameter in OpenReadStream is ever used
rg -n "OpenReadStream.*true\|OpenReadStream(true" src/ --type=cs

Repository: EvilBeaver/OneScript

Length of output: 192


🏁 Script executed:

# Check the full context of where OpenReadStream is called
rg -n "OpenReadStream" src/OneScript.StandardLibrary/Http/ --type=cs -B 2 -A 2

Repository: EvilBeaver/OneScript

Length of output: 2006


🏁 Script executed:

# Check the project file for LangVersion setting
find . -name "*.csproj" -type f | xargs grep -l "StandardLibrary" | head -1 | xargs cat | grep -i "langversion\|targetframework"

Repository: EvilBeaver/OneScript

Length of output: 46


🏁 Script executed:

# Check if lock statements with objects are used elsewhere in the codebase for C# 8 compatibility
rg -n "lock.*\(.*\)" src/OneScript.StandardLibrary/ --type=cs | head -5

Repository: EvilBeaver/OneScript

Length of output: 582


Add thread-safe lazy initialization to prevent concurrent access race condition.

The OpenReadStream() method uses an unsafe check-then-act pattern at lines 87-90. Since HttpResponseContext objects can be passed to background tasks and multiple tasks may call different methods (GetText(), GetBinaryData(), etc.) concurrently, both threads could see _inMemoryResponseInited as false and simultaneously invoke InitInMemoryResponse(), causing concurrent reads on _rawStream.

Add a double-check locking pattern to ensure thread-safe initialization:

+private readonly object _initLock = new object();
+
 public Stream OpenReadStream(bool raw = false)
 {
     if (raw && !_inMemoryResponseInited)
     {
         return GetResponseStream();
     }

     if (!_inMemoryResponseInited)
     {
+        lock (_initLock)
+        {
+            if (!_inMemoryResponseInited)
+            {
-                InitInMemoryResponse();
+                InitInMemoryResponse();
+            }
+        }
     }

     if (_backingFileName != null)
     {
         return new FileStream(_backingFileName, FileMode.Open, FileAccess.Read);
     }
     else if (_inMemBody != null)
     {
         return new MemoryStream(_inMemBody);
     }
     else
         throw new InvalidOperationException("No response body");
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/OneScript.StandardLibrary/Http/HttpResponseBody.cs around lines 80 to
102, the method OpenReadStream uses a check-then-act on _inMemoryResponseInited
that can race when multiple threads call methods that trigger initialization;
introduce a thread-safe double-check locking pattern: add a private readonly
object (e.g. _initLock) for synchronization, perform an initial if
(!_inMemoryResponseInited) check, then lock(_initLock) and re-check if
(!_inMemoryResponseInited) before calling InitInMemoryResponse(), and ensure the
flag is set only once inside the lock so concurrent callers cannot invoke
InitInMemoryResponse simultaneously; keep the existing behavior for raw-mode
early return by applying the same locking/double-check logic where needed.

Copy link
Owner

Choose a reason for hiding this comment

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

Класс не предназначен для доступа из нескольких потоков

Copy link
Contributor

Choose a reason for hiding this comment

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

@EvilBeaver, спасибо за уточнение! Понял, что класс HttpResponseBody предназначен для однопоточного использования, и беспокойство о гонках потоков здесь неуместно.


✏️ Learnings added
Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 1630
File: src/OneScript.StandardLibrary/Http/HttpResponseBody.cs:80-102
Timestamp: 2025-12-13T10:54:25.530Z
Learning: The `HttpResponseBody` class in `src/OneScript.StandardLibrary/Http/HttpResponseBody.cs` is designed for single-threaded access only and does not require thread-safety mechanisms like locking or volatile fields.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 1557
File: src/VSCode.DebugAdapter/Transport/RpcOperationException.cs:11-11
Timestamp: 2025-07-18T12:25:24.078Z
Learning: EvilBeaver prefers to preserve original namespaces for types involved in binary serialization or cross-version compatibility, even if the type is not directly serialized, to maintain overall system compatibility.

Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 1557
File: src/VSCode.DebugAdapter/Transport/DebugClientFactory.cs:60-0
Timestamp: 2025-07-16T12:44:12.167Z
Learning: EvilBeaver prefers fail-fast error handling in debugging contexts - when stream operations fail in debug client factories, exceptions should be thrown to terminate the process rather than handled gracefully with fallback mechanisms.

Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 1555
File: Build.csproj:35-38
Timestamp: 2025-07-10T11:08:13.756Z
Learning: EvilBeaver prefers to see documentation links when technical claims are made about MSBuild syntax and property functions.

Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2024-08-05T18:27:08.563Z
Learning: For each new pull request in the EvilBeaver/OneScript repository, include a poem in Russian.

Убрал лишний таймаут

Revert "Убрал лишний таймаут"

This reverts commit b751058.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b751058 and 45cb9a8.

📒 Files selected for processing (1)
  • tests/http.os (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2024-08-05T18:27:08.563Z
Learning: For each new pull request in the EvilBeaver/OneScript repository, include a poem in Russian.
Learnt from: sfaqer
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2025-05-23T03:00:18.462Z
Learning: User sfaqer prefers communication in Russian language.
📚 Learning: 2025-12-01T15:13:19.064Z
Learnt from: CR
Repo: EvilBeaver/OneScript PR: 0
File: .cursor/rules/runbsltests.mdc:0-0
Timestamp: 2025-12-01T15:13:19.064Z
Learning: Ignore errors from http.os test file and the test named 'Тест_ДолженПроверитьЧтоПеремещениеФайлаРаботаетПоHTTP' when reviewing BSL test results

Applied to files:

  • tests/http.os
🔇 Additional comments (2)
tests/http.os (2)

420-420: Без содержательных изменений (похоже на правку сигнатуры/пробелов).


42-44: Добавление теста в список: ок, но лучше держать “ожидаемое” первым аргументом в проверках нового теста.
Сейчас в новом тесте местами используется обратный порядок аргументов ПроверитьРавенство(факт, ожидаемое), тогда как в остальном файле — ПроверитьРавенство(ожидаемое, факт) (это влияет на читаемость и сообщения об ошибках).

⛔ Skipped due to learnings
Learnt from: CR
Repo: EvilBeaver/OneScript PR: 0
File: .cursor/rules/runbsltests.mdc:0-0
Timestamp: 2025-12-01T15:13:19.064Z
Learning: Ignore errors from http.os test file and the test named 'Тест_ДолженПроверитьЧтоПеремещениеФайлаРаботаетПоHTTP' when reviewing BSL test results

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/global-funcs.os (1)

659-678: Тесты “по HTTP/по HTTPS” больше не гарантируют проверку обеих схем

И в Тест_ДолженПроверитьЧтоКопированиеФайлаРаботаетПоHTTP (Line 659), и в ...ПоHTTPS (Line 677) используется один и тот же мАдресРесурса + "/image". Если мАдресРесурса выберется как https://..., то “HTTP” кейс фактически станет HTTPS (и наоборот). Либо разделите на два адреса (http/https), либо переименуйте тесты под “по URL/ресурсу”.

♻️ Duplicate comments (1)
tests/http.os (1)

398-419: Повторный вызов ПолучитьТелоКакПоток() и незакрытые потоки → риск утечек/флейков

В ТестДолженПроверитьЧтоТелоМожноПолучитьНесколькоРаз (Line 407-418) поток запрашивается несколько раз и не закрывается. Это уже поднималось ранее и выглядит как регресс/повтор проблемы.

Предлагаю минимальную правку:

 Процедура ТестДолженПроверитьЧтоТелоМожноПолучитьНесколькоРаз() Экспорт
@@
-    Ответ.ПолучитьТелоКакПоток();
-
-    юТест.ПроверитьРавенство(Ответ.ПолучитьТелоКакПоток().ДоступноЧтение, Истина);
+    Поток1 = Ответ.ПолучитьТелоКакПоток();
+    юТест.ПроверитьРавенство(Истина, Поток1.ДоступноЧтение);
+    Поток1.Закрыть();
@@
-    // Оригинальный поток уже вычитан вернется поддельный
-    юТест.ПроверитьРавенство(Ответ.ПолучитьТелоКакПоток().ДоступноЧтение, Истина);
+    // Оригинальный поток уже вычитан вернется поддельный
+    Поток2 = Ответ.ПолучитьТелоКакПоток();
+    юТест.ПроверитьРавенство(Истина, Поток2.ДоступноЧтение);
+    Поток2.Закрыть();
🧹 Nitpick comments (3)
tests/global-funcs.os (2)

9-18: Инициализация мАдресРесурса в ПолучитьСписокТестов: возможные сайд-эффекты/флейки при перечислении тестов

ПодключитьСценарий и сетевой ВыбратьДоступныйХост() выполняются на этапе построения списка тестов (Line 14-18). Если раннер вызывает ПолучитьСписокТестов несколько раз или в окружении без сети — можно получить нестабильность до фактического запуска тестов. Рассмотрите ленивую инициализацию (например, в ПередЗапускомТеста/первом HTTP-тесте) или кэш/защиту “если уже инициализировано”.


695-707: ПереместитьФайл тест: хрупкая логика с 405 и чтением временного файла

В ветке Исключение после ПереместитьФайл(...) (Line 695-707) вы читаете Новый ДвоичныеДанные(Приемник), но при некоторых реализациях/хостах файл может не появиться (или появиться нулевой), и тест упадет “не там”. Лучше явно проверить существование/размер файла перед чтением и в любом случае гарантировать очистку временного файла.

tests/http.os (1)

539-569: ВыбратьДоступныйХост() экспорт и новый кандидат: ок, но проверьте приоритеты/стабильность

Экспорт функции полезен для переиспользования (как в global-funcs.os). Добавление https://connectorhttp.ru (Line 556) увеличивает шансы найти рабочий хост, но добавляет зависимость от стороннего сервиса — убедитесь, что порядок кандидатов соответствует желаемому (например, localhost/внутренний стенд прежде публичных).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7766718 and 6260b5b.

📒 Files selected for processing (2)
  • tests/global-funcs.os (4 hunks)
  • tests/http.os (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2024-08-05T18:27:08.563Z
Learning: For each new pull request in the EvilBeaver/OneScript repository, include a poem in Russian.
Learnt from: sfaqer
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2025-05-23T03:00:18.462Z
Learning: User sfaqer prefers communication in Russian language.
📚 Learning: 2025-12-01T15:13:19.064Z
Learnt from: CR
Repo: EvilBeaver/OneScript PR: 0
File: .cursor/rules/runbsltests.mdc:0-0
Timestamp: 2025-12-01T15:13:19.064Z
Learning: Ignore errors from http.os test file and the test named 'Тест_ДолженПроверитьЧтоПеремещениеФайлаРаботаетПоHTTP' when reviewing BSL test results

Applied to files:

  • tests/global-funcs.os
  • tests/http.os
🔇 Additional comments (1)
tests/http.os (1)

42-44: Добавление новых тестов в список: ок
Хорошо, что новые проверки зарегистрированы рядом с родственными тестами.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
src/OneScript.StandardLibrary/Http/HttpResponseBody.cs (1)

80-102: Thread-safety concern on lazy initialization pattern.

The check-then-act pattern on _inMemoryResponseInited (lines 87-90) is not thread-safe. If HttpResponseBody is accessed from multiple threads (e.g., via background tasks), concurrent calls could both see false and invoke InitInMemoryResponse() simultaneously, causing double-reads or corruption of _rawStream.

Consider adding a lock for thread-safe initialization:

+private readonly object _initLock = new object();
+
 public Stream OpenReadStream(bool raw = false)
 {
     if (raw)
     {
         return GetResponseStream();
     }

     if (!_inMemoryResponseInited)
     {
+        lock (_initLock)
+        {
+            if (!_inMemoryResponseInited)
+            {
                 InitInMemoryResponse();
+            }
+        }
     }
     // ...
 }
tests/http.os (1)

399-421: Потоки не закрываются — возможны утечки ресурсов.

Тест многократно вызывает Ответ.ПолучитьТелоКакПоток() без сохранения и закрытия полученных потоков (Lines 408, 410, 419). Это может привести к утечкам ресурсов, особенно если тело сохранено в файл.

Рекомендуемое исправление:

 	Ответ.ПолучитьТелоКакПоток();
-
-	юТест.ПроверитьРавенство(Ответ.ПолучитьТелоКакПоток().ДоступноЧтение, Истина);
+	Поток1 = Ответ.ПолучитьТелоКакПоток();
+	юТест.ПроверитьРавенство(Поток1.ДоступноЧтение, Истина);
+	Поток1.Закрыть();
 
 	// ... остальной код ...
 
 	// Оригинальный поток уже вычитан вернется поддельный
-	юТест.ПроверитьРавенство(Ответ.ПолучитьТелоКакПоток().ДоступноЧтение, Истина);
+	Поток2 = Ответ.ПолучитьТелоКакПоток();
+	юТест.ПроверитьРавенство(Поток2.ДоступноЧтение, Истина);
+	Поток2.Закрыть();
🧹 Nitpick comments (1)
tests/global-funcs.os (1)

675-679: Test name vs behavior mismatch.

Тест_ДолженПроверитьЧтоКопированиеФайлаРаботаетПоHTTPS now uses мАдресРесурса which may resolve to an HTTP host (e.g., http://127.0.0.1:8085), making the "HTTPS" in the test name potentially misleading. Consider renaming to reflect the dynamic nature, or keeping a separate test that explicitly uses HTTPS.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6260b5b and cb898ef.

📒 Files selected for processing (4)
  • src/OneScript.StandardLibrary/Http/HttpResponseBody.cs (6 hunks)
  • src/OneScript.StandardLibrary/Http/HttpResponseContext.cs (1 hunks)
  • tests/global-funcs.os (4 hunks)
  • tests/http.os (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/OneScript.StandardLibrary/Http/HttpResponseContext.cs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (.cursor/rules/langversion.mdc)

Do not use C# language features that are not available in C# 8 when generating code for projects using .NET 8.0 with LangVersion 8

Files:

  • src/OneScript.StandardLibrary/Http/HttpResponseBody.cs
🧠 Learnings (2)
📓 Common learnings
Learnt from: EvilBeaver
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2024-08-05T18:27:08.563Z
Learning: For each new pull request in the EvilBeaver/OneScript repository, include a poem in Russian.
Learnt from: sfaqer
Repo: EvilBeaver/OneScript PR: 0
File: :0-0
Timestamp: 2025-05-23T03:00:18.462Z
Learning: User sfaqer prefers communication in Russian language.
📚 Learning: 2025-12-01T15:13:19.064Z
Learnt from: CR
Repo: EvilBeaver/OneScript PR: 0
File: .cursor/rules/runbsltests.mdc:0-0
Timestamp: 2025-12-01T15:13:19.064Z
Learning: Ignore errors from http.os test file and the test named 'Тест_ДолженПроверитьЧтоПеремещениеФайлаРаботаетПоHTTP' when reviewing BSL test results

Applied to files:

  • tests/global-funcs.os
  • tests/http.os
🔇 Additional comments (8)
src/OneScript.StandardLibrary/Http/HttpResponseBody.cs (2)

82-85: LGTM - Raw stream path correctly bypasses buffering.

The raw=true path returns the underlying stream directly without initializing in-memory state, enabling streaming scenarios where the caller wants to consume data incrementally without buffering the entire response. This aligns with the PR objective.

Note: Callers should be aware that the raw stream can only be consumed once.


104-109: LGTM - Clean refactoring of stream access.

The method correctly uses the stored _rawStream field and handles gzip decompression. The removal of the HttpWebResponse parameter simplifies the internal API.

tests/global-funcs.os (1)

16-19: LGTM - Dynamic host selection improves test reliability.

Lazy initialization of the test host resource via ВыбратьДоступныйХост() is a good approach for avoiding hardcoded external dependencies. This centralizes host selection logic.

tests/http.os (5)

423-437: LGTM - Test correctly verifies body access after stream closure.

This test validates that after obtaining and closing the raw stream, the body can still be retrieved via ПолучитьТелоКакСтроку() because it was buffered in memory. The assertion correctly checks for expected content.


439-462: LGTM - Critical test for PR functionality.

This test correctly validates the core behavior change:

  1. After ПолучитьТелоКакСтроку() is called, the raw stream is consumed
  2. Subsequent ПолучитьТелоКакПоток(Истина) returns an unavailable stream (ДоступноЧтение = Ложь)
  3. Non-raw ПолучитьТелоКакПоток() still works via buffered data

This directly tests the PR's objective of moving stream consumption from initialization to retrieval.


565-565: LGTM - Export enables code reuse.

Exporting ВыбратьДоступныйХост() allows other test modules to leverage the same host selection logic, avoiding duplication.


484-484: LGTM - Raw stream required for SSE streaming.

Using ПолучитьТелоКакПоток(Истина) for the stream event test is correct — SSE requires reading the raw stream incrementally without buffering the entire response first.


581-581: Do not add connectorhttp.ru as a fallback candidate—this is not a valid or publicly accessible HTTP testing service. Standard HTTP testing services are httpbin.org and httpbingo.org. Adding an unreachable host will not improve test reliability. Consider using an established alternative like httpbingo.org instead if additional redundancy is needed.

⛔ Skipped due to learnings
Learnt from: CR
Repo: EvilBeaver/OneScript PR: 0
File: .cursor/rules/runbsltests.mdc:0-0
Timestamp: 2025-12-01T15:13:19.064Z
Learning: Ignore errors from http.os test file and the test named 'Тест_ДолженПроверитьЧтоПеремещениеФайлаРаботаетПоHTTP' when reviewing BSL test results

@EvilBeaver EvilBeaver merged commit 11d8c5f into EvilBeaver:develop Dec 13, 2025
2 checks passed
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.

2 participants