MCPcopy
hub / github.com/nodejs/undici / onResponseData

Method onResponseData

lib/handler/redirect-handler.js:112–134  ·  view source on GitHub ↗
(controller, chunk)

Source from the content-addressed store, hash-verified

110 }
111
112 onResponseData (controller, chunk) {
113 if (this.location) {
114 /*
115 https://tools.ietf.org/html/rfc7231#section-6.4
116
117 TLDR: undici always ignores 3xx response bodies.
118
119 Redirection is used to serve the requested resource from another URL, so it assumes that
120 no body is generated (and thus can be ignored). Even though generating a body is not prohibited.
121
122 For status 301, 302, 303, 307 and 308 (the latter from RFC 7238), the specs mention that the body usually
123 (which means it's optional and not mandated) contain just an hyperlink to the value of
124 the Location response header, so the body can be ignored safely.
125
126 For status 300, which is "Multiple Choices", the spec mentions both generating a Location
127 response header AND a response body with the other possible location to follow.
128 Since the spec explicitly chooses not to specify a format for such body and leave it to
129 servers and browsers implementors, we ignore the body as there is no specified way to eventually parse it.
130 */
131 } else {
132 this.handler.onResponseData?.(controller, chunk)
133 }
134 }
135
136 onResponseEnd (controller, trailers) {
137 if (this.location) {

Callers

nothing calls this directly

Calls 1

onResponseDataMethod · 0.65

Tested by

no test coverage detected