@@ -288,10 +288,6 @@ private function parseErrorResponse(PsrRequest $request, BadResponseException $e
288288 */
289289 private function createDocumentObject (PsrRequest $ request , PsrResponse $ response = NULL ) : ?Objects \IDocument
290290 {
291- if (!$ this ->httpContainsBody ($ request , $ response )) {
292- return NULL ;
293- }
294-
295291 return new Objects \Document (Utils \Json::decode (($ response ? (string ) $ response ->getBody () : (string ) $ request ->getBody ())));
296292 }
297293
@@ -305,93 +301,9 @@ private function createDocumentObject(PsrRequest $request, PsrResponse $response
305301 */
306302 private function createErrorObject (PsrRequest $ request , PsrResponse $ response = NULL ) : ?Objects \IMutableError
307303 {
308- if (!$ this ->httpContainsBody ($ request , $ response )) {
309- return NULL ;
310- }
311-
312304 return Objects \Error::create (Utils \Json::decode (($ response ? (string ) $ response ->getBody () : (string ) $ request ->getBody ()), Utils \Json::FORCE_ARRAY ));
313305 }
314306
315- /**
316- * @param PsrRequest $request
317- * @param PsrResponse|NULL $response
318- *
319- * @return bool
320- */
321- private function httpContainsBody (PsrRequest $ request , ?PsrResponse $ response = NULL ) : bool
322- {
323- return $ response ?
324- $ this ->doesResponseHaveBody ($ request , $ response ) :
325- $ this ->doesRequestHaveBody ($ request );
326- }
327-
328- /**
329- * Does the HTTP request contain body content?
330- *
331- * The presence of a message-body in a request is signaled by the inclusion of a Content-Length or
332- * Transfer-Encoding header field in the request's message-headers.
333- * https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
334- *
335- * However, some browsers send a Content-Length header with an empty string for e.g. GET requests
336- * without any message-body. Therefore rather than checking for the existence of a Content-Length
337- * header, we will allow an empty value to indicate that the request does not contain body.
338- *
339- * @param PsrRequest $request
340- *
341- * @return bool
342- */
343- private function doesRequestHaveBody (PsrRequest $ request ) : bool
344- {
345- if ($ request ->hasHeader ('Transfer-Encoding ' )) {
346- return TRUE ;
347- }
348-
349- if (!$ contentLength = $ request ->getHeader ('Content-Length ' )) {
350- return FALSE ;
351- }
352-
353- return 0 < $ contentLength [0 ];
354- }
355-
356- /**
357- * Does the HTTP response contain body content?
358- *
359- * For response messages, whether or not a message-body is included with a message is dependent
360- * on both the request method and the response status code (section 6.1.1). All responses to the
361- * HEAD request method MUST NOT include a message-body, even though the presence of entity-header
362- * fields might lead one to believe they do. All 1xx (informational), 204 (no content), and 304
363- * (not modified) responses MUST NOT include a message-body. All other responses do include a
364- * message-body, although it MAY be of zero length.
365- * https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
366- *
367- * @param PsrRequest $request
368- * @param PsrResponse $response
369- *
370- * @return bool
371- */
372- private function doesResponseHaveBody (PsrRequest $ request , PsrResponse $ response ) : bool
373- {
374- if (strtoupper ($ request ->getMethod ()) === 'HEAD ' ) {
375- return FALSE ;
376- }
377-
378- $ status = $ response ->getStatusCode ();
379-
380- if ((100 <= $ status && 200 > $ status ) || 204 === $ status || 304 === $ status ) {
381- return FALSE ;
382- }
383-
384- if ($ response ->hasHeader ('Transfer-Encoding ' )) {
385- return TRUE ;
386- }
387-
388- if (!$ contentLength = $ response ->getHeader ('Content-Length ' )) {
389- return FALSE ;
390- }
391-
392- return 0 < $ contentLength [0 ];
393- }
394-
395307 /**
396308 * @param string $baseUri
397309 *
0 commit comments