Skip to content

Match HTTP header Contains and stream write behavior - #7870

Open
bstaeheli wants to merge 5 commits into
aldevtools:mainfrom
bstaeheli:pr-http-header-behavior-current
Open

bstaeheli wants to merge 5 commits into
aldevtools:mainfrom
bstaeheli:pr-http-header-behavior-current

Conversation

@bstaeheli

@bstaeheli bstaeheli commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

No linked issue.

What changed

  • Integrate current main and address the HTTP review feedback without rewriting the existing PR history.
  • For the measured BC versions and shapes, report the observed empty-name header error and preserve the actual Content-Type state across stream writes and copies. Retain the existing receiver and secret-content guards.
  • Register the unpinned behavior as assumptions; refuse unmeasured new shapes while preserving the previous BC 27 behavior outside the measured minor version.

Evidence from real Business Central (required)

  • Probe PR / repro: Probe empty HTTP header names and stream writes BusinessCentral.AL.Language.Tests#1424. Empty-name HttpHeaders.Contains('') raised code InvalidHeader:Argument with text Invalid HTTP header. Please, make sure the format of the header is correct. Stream writes retained the measured existing Content-Type state.
  • BC versions measured: 27.5, 28.5 and 29.1, with the neutral probes passing locally. The probe PR's CI requires maintainer approval; its BC 29.0 result and the official corpus pin remain pending. BC 29.1 is not treated as evidence for BC 29.0.

Where the behavior is pinned

  • The new shapes are not pinned yet: http-contains-empty-name cites the probe at tests/al-language/http/HttpHeaders.al:518 and :545; http-stream-write-keeps-removed-content-type cites tests/al-language/http/content/HttpContent.al:717 and the following probe cases.
  • Existing fresh-stream and secret-to-stream behavior remain pinned by http/headers/P87ContentStream.al:45, queries/joins-links/HttpWriteFromStream.al:113 and xml/xml/P97ContentSecret.al:169.

Shapes that keep today's behavior

The HTTP host regressions cover receiver and secret-content guards, text and fresh-stream writes, header clear, content clear, copies, re-added Content-Type and unmeasured versions or stream states. Existing BC 27 behavior remains for unmeasured BC 27 minors; unmeasured new behavior on later versions is refused. The pinned secret-to-stream case passes on all configured oracle versions.

Checks

  • A test that failed before this change and passes now
  • Tests that neighbor shapes keep main's result
  • al-test-cli --root . --baseline-diff: no regression; stale lines deleted (--prune-not-passing) (or: not run, and why)
  • ./check.sh (or: not run, and why)
  • I signed the contributor agreement (see CONTRIBUTING.md)
  • No machine names, URLs, credentials, tenant ids or customer code in the change or this text

Validation:

  • cargo build --offline --locked --release -p al-test-cli -j 1 — passed.
  • cargo test --offline --locked -p al-builtins -j 1 -- --skip two_branches_that_change_the_registry_merge_cleanly — passed; the skipped Windows shell fixture invokes git add -A and disables commit signing, which this project's agent workflow prohibits.
  • cargo test --offline --locked -p al-vm --test host -j 1 -- http_headers — passed; the new version-boundary regressions were red before their fixes and green afterward.
  • cargo test --offline --locked -p al-test-cli --test fn_length_ratchet --test file_size_ratchet --test os_access_ratchet -j 1 — passed.
  • cargo clippy --offline --locked -p al-builtins -p al-vm --all-targets -j 1 -- -D warnings — passed.
  • cargo fmt --all -- --check and git diff --check — passed.
  • .\target\release\al-test-cli.exe --root . --assumptions-doc — passed; the table is current.
  • .\target\release\al-test-cli.exe --root . --no-download --bc-version $v --file P97ContentSecret.al --explain Secret_WriteFromInStream — passed for $v 27, 28 and 29.
  • .\target\release\al-test-cli.exe --root . --no-download --bc-version $v --baseline-diff --prune-not-passing --junit $xml — ran for $v 27, 28 and 29 with $xml a session-local output file and a locally built compatible .NET sidecar. Each exited 1 on existing Windows baseline discrepancies. A release build of unmodified main reproduced the affected results; JUnit outcomes and messages for those cases match the final branch. No HTTP regressions, missing outcomes or stale list entries were reported.
  • ./check.sh and a full workspace test were not run locally, per the project's PR-CI workflow.
  • The runtime PR's CI is also waiting for maintainer approval (action_required).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 13:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Deep copies lose the Content-Type removal flag, while empty-name Contains and stream-after-removal behavior lack the required probe PRs and BC-backed evidence.

3 open issues
What changed in this PR

This PR updates the Rust AL runtime’s HTTP behavior for empty header-name lookups and stream writes after Content-Type removal.

Changes:

  • Makes HttpHeaders.Contains('') raise InvalidHeader:Argument on supported versions.
  • Tracks explicit Content-Type removal so stream writes preserve its absence, while retaining text-write and fresh-stream behavior.
  • Adds focused regression tests and documents both behaviors as assumptions awaiting corpus probes.
File Description
docs/​probes-needed.md Documents the two assumptions and required probes.
crates/​al-vm/​tests/​host/​http_headers.rs Tests empty-name lookups and Content-Type behavior across writes.
crates/​al-builtins/​src/​value.rs Adds state tracking explicit Content-Type removal.
crates/​al-builtins/​src/​http/​headers.rs Records removal and handles empty-name Contains calls.
crates/​al-builtins/​src/​http/​content.rs Distinguishes stream and text writes when restoring Content-Type.
crates/​al-builtins/​src/​assumptions/​http-stream-write-keeps-removed-content-type.rs Registers the stream-write assumption.
crates/​al-builtins/​src/​assumptions/​http-contains-empty-name.rs Registers the empty-name Contains assumption.

Review effort: Balanced

Comment thread crates/al-builtins/src/http/content.rs Resolved

@StefanMaron StefanMaron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi Boris, thank you for this pull request. The code is small and easy to read, both changes sit in the right owner functions, and you registered both behaviors as assumptions with tests that check the flag. That is the right structure. I read the diff only; I did not build or run it.

I cannot merge it yet. The reason is our rule for new behavior: every answer the runner gives needs a test in the corpus repository that real Business Central passed, or an assumption that cites an open probe pull request on the corpus repository plus the evidence behind it. Both changes are missing that evidence today.

1. Contains('') raising InvalidHeader:Argument

  • The assumption cites AyHeaderAddResult.al:159. That case measures Add('', 'v') and a GetValues afterwards. It does not measure Contains. So the new answer comes from an analogy.
  • The analogy is not safe. The corpus has a lookup with an empty name that does not raise: GetSecretValues with an empty name answers false (P97HdrSecretValues.al:103-105).
  • Did you see this on a real Business Central? If yes, please tell me the version and the error code and text you got. That counts as evidence.
  • What I need: a probe in the corpus repository (Contains('') on request, content, response and client headers, inside a TryFunction, with GetLastErrorCode and GetLastErrorText). The assumption text then cites that pull request.
  • On BC 27 the new code refuses. main answers false there today. A test that ran on BC 27 would stop running. Please keep main's answer on BC 27 until a probe measures it.
  • The new check runs before the collection is looked at. So it can also change the answer for a header variable that was never filled, and for the headers of a secret content, which main refuses (I did not run these). Please keep the existing order and put the new check after those.

2. Stream write after Remove('Content-Type')

  • The cited case P87ContentType.al:WriteAfterRemovedType (line 137) measures the text write only. It pins the half you kept, not the half you changed. No corpus case writes a stream after a Remove.
  • So the same question: what did you measure, and where? With your repro and a probe pull request, this can land as an assumption.
  • The new flag content_type_removed is set once and never cleared. Example: Remove('Content-Type'), then WriteFrom('text') (the header is back), then H.Clear(), then WriteFrom(InStream). The flag is still set from the first step, so the header stays absent. main puts it back, and nothing measured that sequence.
  • The flag is also set when the content never had a Content-Type (Remove on fresh content, then a stream write). The fresh stream case in the corpus has no Remove, so this is a third shape nobody measured.
  • Please limit the new path to the exact sequence you measured (write, remove, stream write, nothing in between), clear the flag whenever the header is set again or the headers are cleared, and let every other sequence keep main's answer. Please add tests for those neighbor sequences.
  • HttpContent.Clear followed by a stream write: please check the flag does not survive it.

3. Small things

  • The doc comment on write_body now mixes the pinned text rule and the assumed stream rule in one sentence. Please keep them apart, so a reader sees what is pinned.
  • The citations name a test (:WriteAfterRemovedType) and a folder (network/lt-ay-http/) that does not match the file's place in the corpus. We cite file:line.
  • All CI checks are green.

Your note about the assumptions test on Windows

You are right, and it is our bug, not yours. The helper sources() in crates/al-builtins/src/assumptions.rs keeps only paths that contain /src/. On Windows the separator is \, so the list is empty and every_entry_is_marked_somewhere reports every entry as unused. Our Windows check in CI only compiles; it does not run this test, so we never saw it. We will fix it on our side by comparing path components instead of text. You do not need to touch it in this pull request. Thank you for reporting it.

If anything here is unclear, or you want me to write the two probes, please say so.

Please measure these cases yourself on a real BC (27, 28 and 29) and bring the probe with the pull request; that is the part I can't take over for contributions.

Merge the pull request with current main for review.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve header state across copies and refuse unmeasured shapes. Record the local BC evidence until the probe is pinned.

Refs aldevtools/BusinessCentral.AL.Language.Tests#1424

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bstaeheli

Copy link
Copy Markdown
Contributor Author

The requested neutral probe is open in aldevtools/BusinessCentral.AL.Language.Tests#1424 and passed locally on BC 27.5, 28.5 and 29.1. For Contains(''), the observed code is InvalidHeader:Argument and the text is Invalid HTTP header. Please, make sure the format of the header is correct.

The runtime retains the receiver and secret-content guards. The removal flag is gone; copies use the actual header state. Unmeasured neighboring shapes keep main's behavior or refuse. The PR description records the validation results.

Both PR workflows need maintainer approval. The corpus pin is pending, BC 29.0 is not claimed as measured, and the review threads remain open.

@StefanMaron

Copy link
Copy Markdown
Collaborator

Thanks for opening the probe as aldevtools/BusinessCentral.AL.Language.Tests#1424, with the observed code InvalidHeader:Argument and its text.

Before I review the code, the diff needs to get smaller. It now shows 719 files (+212,302/-105,440), including oracle/28/junit.xml, oracle/29/junit.xml and the other oracle files, the workflows and CLAUDE.md. A pull request never changes oracle/. Most of these files look like line-ending changes or an older copy of main. Please update the branch from current main and drop every file your fix does not need, so the diff shows only the HTTP change and its tests. Then I review it, and I approve the CI runs here and on the probe.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bstaeheli

Copy link
Copy Markdown
Contributor Author

Hi Stefan, thanks for taking the time to look at this and for the clear feedback!

You're right: the PR still shows a large unrelated diff, including oracle files. Sorry about that. I'll update the branch against current main and clean up the diff before asking you to review it or approve CI.

Thanks also for reviewing the probe first — I appreciate your help!

@StefanMaron

Copy link
Copy Markdown
Collaborator

Thanks, Boris. This round fixes everything from my first review, and the probe is thorough. I built the branch and
ran your probe cells on BC 27.5, 28.5 and 29.1: every one gives your measured result and is reported as flagged.
Main gets most of them wrong today. I also ran the http, xml and queries areas of the corpus on 27, 28 and 29
with your branch: no regressions. I'm approving the CI run for this pull request now. The corpus runs one probe CI at a time, so probe 1424 comes right after probe 1364.

One thing before I can merge:

The assumption for Contains('') says it covers a "fresh" header collection. The check in headers_contains tests
whether the collection is empty right now, not whether it is fresh. So these three cases also raise the error,
flagged, and your probe does not measure them:

  • request headers after Add('X-A', 'v') and Remove('X-A')
  • client default headers after Add and then Clear()
  • content headers after removing and re-adding 'text/plain; charset=utf-8'

I expect BC raises the same error for all of them, since the error comes from the empty name. The easiest fix is
to add these three cases to probe 1424, and then reword the entry to "a request, response or client header
collection with no headers, or content headers that hold only the default Content-Type". Please also add your
third Contains test (HttpHeaders.al:566, request content after a write) to the entry's probe and files. The
code already handles that case; the entry just does not mention it yet.

For later, no need to do it in this pull request: the version check accepts 27.5, 28.5 and 29.1 only. The corpus CI
and runs without --bc-version use 29.0, so both paths are refused there for now. Once the corpus CI for 1424 is
green on 29.0, we can add it.

@StefanMaron

Copy link
Copy Markdown
Collaborator

One more thing from the CI run I approved. The test check fails in no_version_literals (no_crate_outside_al_version_spells_a_bc_version). Since your last main merge, main rejects BC version names in source files outside the al-version crate. The texts of both assumption entries name versions, in lines 3 to 5 of http-contains-empty-name.rs and http-stream-write-keeps-removed-content-type.rs. Please describe the measured builds without the version names, for example "on the builds the probe ran on". The version check in the code can stay as it is.

With that and the points from my review above, the rest of the checks are green.

@StefanMaron

Copy link
Copy Markdown
Collaborator

Thank you for this pull request, and for writing the corpus probe. I am sorry the review took 10 days.

Verdict: needs a rebase on main, then changes. Conflicts: crates/al-builtins/src/native/tests.rs and docs/probes-needed.md, both mechanical. After the rebase, regenerate docs/probes-needed.md with --assumptions-doc instead of merging the table by hand. CI is red because of this pull request (see "Blocking").

Blocking: CI is red. Job test, test no_crate_outside_al_version_spells_a_bc_version. The lines crates/al-builtins/src/assumptions/http-contains-empty-name.rs:3-5 and crates/al-builtins/src/assumptions/http-stream-write-keeps-removed-content-type.rs:3-5 spell BC version names in assumed, tests and probe. Main no longer allows version names in assumption text. Say "the three minors the probe measured (see al-version)" instead, and keep the minor list in al-version (item 1).

  1. MED - crates/al-builtins/src/http/mod.rs:29-33 and crates/al-builtins/src/native/ctx.rs:116. http_probe_measured matches (version.major, version.minor) against the measured minors, and you added Ctx::bc_version() so builtins can read the raw version. ADR-015 3.4 says code asks Target::has and never compares a version. Main keeps minor-specific facts as data in al-version (feature_key_rows and NOTIFICATION_BAR_PLATFORMS in crates/al-version/src/gates.rs).
    Fix: add one fact in al-version, for example pub fn http_probe_1424_measured(t: Option<&Target>) -> bool, matching exactly the measured minors, with a comment naming the corpus PR 1424 files and lines. Reach it through a defaulted Ctx method that answers that fact (default false). Delete Ctx::bc_version() and its two implementations. Keep your host tests in al-vm/tests/host/http_headers.rs.
  2. MED - crates/al-builtins/src/http/content.rs, keep_stream_content_type (about lines 114-147). The gate admits a content state the probe did not measure: content that was read (ReadAs Text) since the last write. Every probe case in corpus PR 1424 (HttpContent.al:717-793) reads only after the stream write. Example: C.WriteFrom('x'); C.ReadAs(T); C.GetHeaders(H); H.Clear(); C.WriteFrom(InS) on a fresh Blob stream. Your branch gives a flagged pass with Content-Type absent. Main gives text/plain. Neither is measured. The assumption must cover only measured shapes. This one is narrow, because ReadAs adds a Content-Length, so only clearing every header reaches it.
    Fix: require "no ReadAs since the last WriteFrom" (a field on HttpContentState set by read_as, cleared by write_body and clear_body), else refuse. Or have the probe measure it and add it to the assumption text. Neighbor app tests/neighbors/http-stream-write-content-type/ should hold that shape plus one fact flipped per test: (a) ReadAs before the stream write, (b) a partly read InStream, (c) an InStream not on a Blob field, (d) a second WriteFrom(InStream), (e) Content-Type application/json; charset=utf-8. Each must refuse on your branch.
  3. LOW - PR body. It says "preserving the previous BC 27 behavior outside the measured minor version" and "Existing BC 27 behavior remains for unmeasured BC 27 minors". The code refuses on every unmeasured minor, and your test http_probe_changes_are_refused_on_unmeasured_versions asserts that. The line about CI waiting for approval is stale. Please rewrite both. Also state plainly that on the runner's own BC 29 leg, both new paths refuse where main answered Contains('') = false and stream write = text/plain. Both main answers contradict the probe, so the refusal is the intended direction.
  4. LOW - http/headers.rs:252-270. The gate also serves content headers holding only text/plain after a text write (request content) and empty response content. That is probe test HttpHeaders_ContainsEmpty_RequestAndResponseContentError (HttpHeaders.al, after line 545). It is missing from awaiting.files, and the entry text says "fresh ... content". Add the test id and say "request content after a text write, fresh response content".
  5. LOW - content.rs. The new !measured_stream refusal has no test with a measured header state. Add one host test: Content-Type removed on a measured minor, an InStream read 3 characters first, expect Unsupported and the stream not handed to the content.
  6. LOW - content.rs. write_body cites http/headers/P87ContentStream.al:45 (a var line, the procedure is line 44). keep_stream_content_type cites xml/xml/P97ContentSecret.al:169 (also a var line). Point both at the procedure lines.

The corpus probe pull request (corpus repo PR 1424) still needs its CI run, because you are an outside contributor and the workflow needs maintainer approval. I will handle that. If BC 29.0 matches, we add it to the al-version fact afterwards.

The review flow changed on 2026-11-21. After the fixes, merge main, add the neighbor folder (tests/neighbors/<topic>/ with a neighbor app and differences.tsv, or none.txt), and run tools/neighbor-diff.sh --changed. Paste its table into the pull request, push once, and post a comment with the words "ready for review" when the draft CI is green. The steps are in CONTRIBUTING.md, section "How a pull request gets reviewed".

Generated by an AI agent (Claude) working for Stefan Maron.

@StefanMaron

Copy link
Copy Markdown
Collaborator

Thank you for this pull request, and sorry it waited so long without a review. I'm going to finish it on our side now, so you do not need to do anything more: we merge the current main, add the neighbor check folder the new review flow needs, review it and land it. Your commits stay in the history with your name. If you would rather finish it yourself, say so here and I'll stop.

Generated by an AI agent (Claude) working for Stefan Maron.

This branch has not been deployed

No deployments
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.

3 participants