[bugfix] http-client: support the src attribute on http:body (#6510)#6511
Conversation
|
I'd like to have #6503 pulled in first... |
| "let $response := http:send-request(\n" + | ||
| " <http:request method='POST' href='" + baseUrl() + "/echo'>\n" + | ||
| " <http:body media-type='text/plain' src='/db/http-src-body.txt'/>\n" + | ||
| " </http:request>)\n" + | ||
| "return parse-json($response[2])?body"); |
There was a problem hiding this comment.
use text block in combination with formatted for better readability
| HTTP_NS + | ||
| "http:send-request(\n" + | ||
| " <http:request method='POST' href='" + baseUrl() + "/echo'>\n" + | ||
| " <http:body src='/db/http-src-body.txt'/>\n" + | ||
| " </http:request>)"); |
There was a problem hiding this comment.
use text block in combination with formatted for better readability
Per @reinhapa's review of PR eXist-db#6511: - Replace the two try/catch + fail() exception tests (HC004, HC005) with assertj assertThatExceptionOfType(...).isThrownBy(...).withStackTraceContaining(...). withStackTraceContaining preserves the original message-plus-cause matching (the error code can surface in the cause chain). Declare assertj-core as a test dependency in the module pom (version is managed in exist-parent). - Convert the three new query strings to text blocks with formatted(baseUrl()). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] Thanks @reinhapa. Addressed in 79b9cb9:
Module tests stay green (76/76). |
…zation The native EXPath HTTP Client ignored the @method attribute on http:body, so an inline body could only be XML-serialized or sent as text -- a binary/base64/hex inline body could not be sent at all (only http:body/@src, added in eXist-db#6510/eXist-db#6511, delivered raw bytes). RequestBuilder now honors @method (EXPath HTTP Client 3.1): - binary / base64: the body's content is base64-decoded and sent as raw bytes. - hex: the content is hex-decoded and sent as raw bytes. - text: the content's string value is sent (an element child is serialized as its text, not its markup). - xml / xhtml / html (or no @method): unchanged -- child elements are XML-serialized as before. Malformed base64/hex content raises err:HC005. The string value of body content is computed by an explicit recursive walk, because the in-memory DOM's getTextContent does not recurse into element children of a constructed http:body. Multipart-part @method, JSON/adaptive serialization, and multiple external $bodies remain follow-ups (eXist-db#6512). SendRequestFunctionTest gains bodyMethodBinarySendsDecodedBytes, bodyMethodHexSendsDecodedBytes, and bodyMethodTextSerializesAsText. Part of eXist-db#6512 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Per @reinhapa's review of PR eXist-db#6511: - Replace the two try/catch + fail() exception tests (HC004, HC005) with assertj assertThatExceptionOfType(...).isThrownBy(...).withStackTraceContaining(...). withStackTraceContaining preserves the original message-plus-cause matching (the error code can surface in the cause chain). Declare assertj-core as a test dependency in the module pom (version is managed in exist-parent). - Convert the three new query strings to text blocks with formatted(baseUrl()). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79b9cb9 to
ed9c6cc
Compare
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] Rebased onto current |
|
Would you rebase a last time now that the flakiness of tests should be resolved (that at least is my understanding). |
The native EXPath HTTP Client did not implement http:body/@src (EXPath HTTP Client spec 3.1): the attribute was parsed away and an empty body was sent, with no error. RequestBuilder now reads @src, and SendRequestFunction resolves the linked resource to the request body bytes. - @src is resolved like fn:doc via SourceFactory, so a database path (/db/... or xmldb:), a file: URI, or an http:/classpath location all work; the resource bytes are sent verbatim with @media-type as the Content-Type. This matches the EXPath reference impl (BaseX), which writes the src resource's raw bytes. - Per the spec, when @src is present the body must have no content and no attribute other than media-type -> err:HC004 (the code was already defined but never thrown). media-type is mandatory on the body -> err:HC005 (a request-validity error; HC004 is reserved for the src/content conflict). Resolution happens between parse and build (it needs the broker from the query context), so the built HttpRequest carries the resolved bytes. SendRequestFunctionTest gains bodySrcSendsResourceContent (a stored db resource is sent as the body and echoed back), bodySrcWithContentThrowsHC004, and bodySrcWithoutMediaTypeThrowsHC005. Closes eXist-db#6510 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Per @reinhapa's review of PR eXist-db#6511: - Replace the two try/catch + fail() exception tests (HC004, HC005) with assertj assertThatExceptionOfType(...).isThrownBy(...).withStackTraceContaining(...). withStackTraceContaining preserves the original message-plus-cause matching (the error code can surface in the cause chain). Declare assertj-core as a test dependency in the module pom (version is managed in exist-parent). - Convert the three new query strings to text blocks with formatted(baseUrl()). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ed9c6cc to
310ce21
Compare
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] Rebased onto current |
…zation The native EXPath HTTP Client ignored the @method attribute on http:body, so an inline body could only be XML-serialized or sent as text -- a binary/base64/hex inline body could not be sent at all (only http:body/@src, added in eXist-db#6510/eXist-db#6511, delivered raw bytes). RequestBuilder now honors @method (EXPath HTTP Client 3.1): - binary / base64: the body's content is base64-decoded and sent as raw bytes. - hex: the content is hex-decoded and sent as raw bytes. - text: the content's string value is sent (an element child is serialized as its text, not its markup). - xml / xhtml / html (or no @method): unchanged -- child elements are XML-serialized as before. Malformed base64/hex content raises err:HC005. The string value of body content is computed by an explicit recursive walk, because the in-memory DOM's getTextContent does not recurse into element children of a constructed http:body. Multipart-part @method, JSON/adaptive serialization, and multiple external $bodies remain follow-ups (eXist-db#6512). SendRequestFunctionTest gains bodyMethodBinarySendsDecodedBytes, bodyMethodHexSendsDecodedBytes, and bodyMethodTextSerializesAsText. Part of eXist-db#6512 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
[This PR was prompted by Joe, drafted by Claude Code, and reviewed by Joe.]
Summary
Implements the
srcattribute onhttp:bodyin the native EXPath HTTP Client, fixing #6510. Previously@srcwas parsed away and an empty body was sent with no error — so e.g. aPUTwith<http:body media-type='text/plain' src='/db/tmp/test.txt'/>stored an empty resource.Closes #6510
What changed
RequestBuilder—http:bodyparsing now reads@src. When present, the body is the linked resource rather than the element's content.resolveBodySource(XQueryContext)resolves@srcto the request-body bytes, andapplyBodysends them with@media-typeas theContent-Type.SendRequestFunction— callsresolveBodySource(context)betweenparseandbuild(resolution needs the broker from the query context), so the builtHttpRequestcarries the resolved bytes.Spec conformance (EXPath HTTP Client 3.1)
@srcis resolved likefn:doc, viaSourceFactory: a database path (/db/…orxmldb:), afile:URI, or anhttp:/classpath location all work; the resource bytes are sent verbatim. This matches the EXPath reference implementation (BaseX), which writes thesrcresource's raw bytes.err:HC004(the code was already defined inHttpClientModulebut never thrown) is raised for the spec's conflict conditions:@srccombined with body content, or@srcwith any attribute other thanmedia-type.media-typeis mandatory on the body, raised aserr:HC005(a request-validity error — HC004 is reserved for the src/content conflict, matching eXist's own HC004 description and BaseX's "media-type is mandatory" behavior).Test plan
SendRequestFunctionTest.bodySrcSendsResourceContent— stores a db resource, sends it via@srcto an echo endpoint, and asserts the body was transmitted (uses the existing embeddedHttpServerharness; no external service).SendRequestFunctionTest.bodySrcWithContentThrowsHC004—@srcplus inline content raiseserr:HC004.SendRequestFunctionTest.bodySrcWithoutMediaTypeThrowsHC005—@srcwithoutmedia-typeraiseserr:HC005.SendRequestFunctionTestgreen (76/76).Note
This touches
RequestBuilder, which #6503 (the HttpClient caching/JMX refactor) is also revising. The two are independent in intent — #6503 is a refactor, this is a missing-feature fix — but whichever merges second will need a small rebase inRequestBuilder.