Skip to content

feat(http_server source): add configuration for custom HTTP responses#25108

Open
stigglor wants to merge 12 commits into
vectordotdev:masterfrom
stigglor:http-responses
Open

feat(http_server source): add configuration for custom HTTP responses#25108
stigglor wants to merge 12 commits into
vectordotdev:masterfrom
stigglor:http-responses

Conversation

@stigglor

@stigglor stigglor commented Apr 2, 2026

Copy link
Copy Markdown

By default the http_server source returns a fixed status code with an empty body. This PR lets users define a VRL program that builds the response per request, so the source can return custom status codes, bodies, and headers, for example to validate payloads and reject bad input with a meaningful error.

The program receives the decoded, enriched events as input (. is an array of event objects) and returns either:

  • A string, used as the response body with the configured response_code, or
  • An object with optional status, body, and headers fields.
  • Early rejection with abort: abort suppresses event forwarding and responds immediately.
  • Acknowledgements: when enabled, a program response is only sent if the sink delivers the events, otherwise the client gets 500 or 400. abort responses are sent before events reach the sink and are never overridden.

How did you test this PR?

Added unit tests which cover the response shapes (string and object returns, custom headers), build-time validation of the VRL program, abort-based early rejection (including JSON object messages and reject_code fallbacks), and the acknowledgement interaction (sink failure overrides a normal response, but never an abort response).

Also verified end-to-end with a pipeline using a response_source program with if/else branches returning different status codes, headers, and bodies.

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

Closes: #21013

@stigglor stigglor requested review from a team as code owners April 2, 2026 05:32
@github-actions github-actions Bot added domain: sources Anything related to the Vector's sources domain: external docs Anything related to Vector's external, public documentation labels Apr 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4325165f04

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/util/http/prelude.rs
Comment thread src/sources/util/http/prelude.rs
@iadjivon

iadjivon commented Apr 2, 2026

Copy link
Copy Markdown

Hi there,

I've added a work in progress label on this PR on behalf of the Documentation team. Please remove this once the Vector team has approved this PR and we will review.

Thanks!

@pront pront added the meta: awaiting author Pull requests that are awaiting their author. label Apr 6, 2026
@github-actions github-actions Bot removed the meta: awaiting author Pull requests that are awaiting their author. label Apr 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6f8cb6840

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/util/http/prelude.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a43240ae4e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/util/http/prelude.rs
Adds a `response_source` configuration option to the `http_server` source that accepts a VRL
program to generate a custom HTTP response for each request.

Closes: vectordotdev#21013
@stigglor stigglor changed the title feat(http_source): add configuration for custom HTTP responses feat(http_server source): add configuration for custom HTTP responses Apr 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27d967bf57

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/http_server.rs
- Added a note for Non-log events being dropped
- Added a note for EventMetadata::default()` loses vector-namespace metadata
- Added fix for u16 truncation wraps out-of-range status codes
- Added fix for JSON abort message without control keys silently drops body

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 689682438b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/util/http/prelude.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05b45681be

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/util/http/prelude.rs
@github-actions github-actions Bot added the docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. label May 5, 2026
@pront pront added the source: http_server Anything `http_server` source related label May 24, 2026
stigglor added 2 commits June 24, 2026 20:13
The master merge added response_source and reject_code to
SimpleHttpSource. This sets both fields in the three enrich_events tests
so the test build compiles, fixes import ordering in the http prelude,
and regenerates the http and http_server component docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7c0cea50a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/util/http/prelude.rs Outdated
stigglor added 3 commits June 26, 2026 11:11
… of dropping events

A response_source program builds response headers from event data, so an invalid
header name or value (for example a value containing CR/LF) put the response builder
into an error state. build_vrl_response then returned a 500 before send_batch ran,
turning a malformed optional header into dropped input events.

Validate each header name and value up front and insert via headers_mut, skipping
any invalid header with a warning. The accepted batch is always forwarded, and the
rest of the response is returned intact.
…at build

compile_response_source only checked that the VRL program compiled, so a program
like `response_source = "1"` was accepted even though the runtime can only turn a
string or object into a response. Such a value hit the `unexpected type` branch at
request time, returned a 500, and dropped the batch.

Validate the program's result type at build, rejecting anything that cannot be a
string or object. Programs that always `abort` have a `never` result type and are
still allowed.
The response_source program builds its input from log events only. When a decoder that
emits metric or trace events (native, native_json, otlp) is configured, those events are
still forwarded to the sink but are absent from `.`, so logic such as `length(.)` accounts
only for log events. Document this so the limitation is explicit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 966bff655c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sources/http_server.rs Outdated
… build

The return-type check accepted any program whose result contained a supported kind, so a
union like `if cond { "ok" } else { 1 }` passed and then dropped the batch with a 500 on
the integer branch. Require the result to be a subset of the supported kinds (string,
object, or an abort-only `never`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain: external docs Anything related to Vector's external, public documentation domain: sources Anything related to the Vector's sources source: http_server Anything `http_server` source related work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http sources should be able to customise the response sent back to clients

3 participants