You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Read the model from the body whatever the Content-Type - #238
body_inspector.go skipped body inspection whenever Content-Type wasn't JSON. That covered curl's default -d (form-urlencoded), text/plain, a missing header and vnd.api+json. A named request such as {"model":"nomic-embed-text"} then routed as if it named no model, to any compatible host, including hosts that don't serve the model.
The inspector now decides from the body:
Multipart bodies, any Content-Encoding, and bodies whose first non-whitespace byte isn't { are skipped.
It peeks through a 256-byte window. Leading whitespace is capped at 4 KiB, so scanning stays linear.
The body is restored byte-for-byte. On a read error, the consumed prefix is restored and the error is replayed.
Chunked bodies over 1 MiB behave as on main.
Type of change
Bug fix
Documentation
How was this tested?
New tests:
TestBodyInspector_BodyDecidesNotContentType: 24 content-type and body shapes.
TestBodyInspector_PeekWindowBoundary.
TestBodyInspector_ChunkedLimitBoundary.
TestBodyInspector_PartialBodySurvivesReadError.
TestBodyInspector_LeadingWhitespaceIsBounded: counts bytes read, not time.
TestProxyRouting_NamedModelIgnoresContentType.
The test that used to require skipping text/plain now expects the model.
The inspector benchmark went from 54 to 57 allocs/op with no measurable latency change.
Live run on integration/test-october at 85f9244, re-checked at c9d134c: a named BAAI/bge-m3 sent as form, text/plain, no header and JSON reached only the vLLM host every time.
Checklist
make ready passes at 67a8de7
Tests added or updated for the change
Documentation updated: api-reference/overview.md (Content-Type is optional), concepts/model-aliases.md, and the v0.0.30 release note
No new dependencies added
Out of scope: real form and multipart bodies still route as if no model was named.
Summary by CodeRabbit
New Features
Model routing can now identify a model in a JSON object body regardless of the Content-Type header, while forwarding the request body and header unchanged.
Multipart, form-encoded and compressed request bodies are not inspected.
Documentation
Clarified that Content-Type: application/json is recommended, not required, and that the request body must be a JSON object with a top-level model field.
Body inspection now identifies eligible JSON-object request bodies without relying on Content-Type. The body is restored for downstream readers. Tests, API guidance, troubleshooting guidance, and release notes cover the updated behaviour.
Changes
Request body inspection and routing
Layer / File(s)
Summary
Body inspection and restoration internal/core/constants/content.go, internal/adapter/inspector/body_inspector.go, internal/adapter/inspector/body_inspector_test.go
Inspection now skips multipart and content-encoded bodies, and checks other bodies for a JSON-object prefix. Tests cover model extraction, bounded scanning, body restoration, and read and close behaviour.
Routing verification and documentation internal/app/handlers/handler_proxy_body_content_type_test.go, docs/content/api-reference/overview.md, docs/content/concepts/model-aliases.md, docs/content/about/release-notes.md
The proxy-routing test checks named-model selection across Content-Type variants and confirms unchanged body forwarding. The documentation describes the updated body-inspection behaviour.
thushan/olla#235: Both changes affect model-based request routing. PR #235 changes how bare Ollama model names resolve for routing, statistics, and sticky keys.
Suggested reviewers: dnnspaul
Merge Risk: Low · up to d4513
A narrow read-error case may be hidden from downstream readers, and troubleshooting advice can mislead users whose bodies are excluded from inspection. These should be fixed, but the current evidence indicates bounded merge risk.
Finishing Touches
📝 Generate docstrings
Commit to this branch
Create a new PR
🧪 Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
body_inspector.goskipped body inspection wheneverContent-Typewasn't JSON. That covered curl's default-d(form-urlencoded),text/plain, a missing header andvnd.api+json. A named request such as{"model":"nomic-embed-text"}then routed as if it named no model, to any compatible host, including hosts that don't serve the model.The inspector now decides from the body:
Content-Encoding, and bodies whose first non-whitespace byte isn't{are skipped.Type of change
How was this tested?
New tests:
TestBodyInspector_BodyDecidesNotContentType: 24 content-type and body shapes.TestBodyInspector_PeekWindowBoundary.TestBodyInspector_ChunkedLimitBoundary.TestBodyInspector_PartialBodySurvivesReadError.TestBodyInspector_LeadingWhitespaceIsBounded: counts bytes read, not time.TestProxyRouting_NamedModelIgnoresContentType.The test that used to require skipping
text/plainnow expects the model.The inspector benchmark went from 54 to 57 allocs/op with no measurable latency change.
Live run on
integration/test-octoberat85f9244, re-checked atc9d134c: a namedBAAI/bge-m3sent as form,text/plain, no header and JSON reached only the vLLM host every time.Checklist
make readypasses at67a8de7api-reference/overview.md(Content-Type is optional),concepts/model-aliases.md, and the v0.0.30 release noteOut of scope: real form and multipart bodies still route as if no model was named.
Summary by CodeRabbit
Content-Typeheader, while forwarding the request body and header unchanged.Content-Type: application/jsonis recommended, not required, and that the request body must be a JSON object with a top-levelmodelfield.