Moshe Rubin
Moshe Rubin

Reputation: 1982

Why does Amazon S3 return "MissingRequestBodyError" ("Request Body is empty")?

When performing a "Delete Multiple Object" operation against the Amazon S3 server, my app receives an HTTP 400 ("Bad Request", and an Amazon S3 error code of "MissingRequestBodyError" with a message of "Request Body is empty". According to the Amazon S3 documentation:

This happens when the user sends an empty xml document as a request. The error message is, "Request body is empty."

As can be see in the following packet trace, the app is passing a very large XML document of 15411 bytes. Can anyone tell me why S3 thinks the XML document is empty?

Here is the request:

000000: 50 4f 53 54 20 2f 3f 64 65 6c 65 74 65 20 48 54  POST /?delete HT
000010: 54 50 2f 31 2e 31 0d 0a 41 63 63 65 70 74 3a 20  TP/1.1..Accept: 
000020: 2a 2f 2a 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a  */*..User-Agent:
000030: 20 6c 69 62 63 75 72 6c 2f 37 2e 32 38 2e 30 20   libcurl/7.28.0 
000040: 4f 70 65 6e 53 53 4c 2f 30 2e 39 2e 38 6a 20 4d  OpenSSL/0.9.8j M
000050: 6f 62 69 6c 65 4d 61 67 6e 65 74 2f 32 2e 31 2e  obileMagnet/2.1.
000060: 31 30 35 2d 57 69 6e 64 6f 77 73 0d 0a 48 6f 73  105-Windows..Hos
000070: 74 3a 20 00 00 00 00 00 00 00 00 00 00 00 00 00  t: xxxxxxxxxxxxx
000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  xxxxxxxxxxxxxxxx
000090: 00 00 00 00 00 00 00 00 2e 73 33 2e 61 6d 61 7a  xxxxxxxx.s3.amaz
0000a0: 6f 6e 61 77 73 2e 63 6f 6d 0d 0a 44 61 74 65 3a  onaws.com..Date:
0000b0: 20 53 75 6e 2c 20 32 31 20 46 65 62 20 32 30 31   Sun, 21 Feb 201
0000c0: 36 20 31 36 3a 32 30 3a 31 36 20 2b 30 30 30 30  6 16:20:16 +0000
0000d0: 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68  ..Content-Length
0000e0: 3a 20 31 35 34 31 31 0d 0a 43 6f 6e 74 65 6e 74  : 15411..Content
0000f0: 2d 4d 44 35 3a 20 6a 73 4c 61 37 39 57 37 31 32  -MD5: jsLa79W712
000100: 45 64 44 68 68 4a 42 72 46 55 37 51 3d 3d 0d 0a  EdDhhJBrFU7Q==..
000110: 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70  Content-Type: ap
000120: 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d  plication/x-www-
000130: 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d  form-urlencoded.
000140: 0a 41 75 74 68 6f 72 69 7a 61 74 69 6f 6e 3a 20  .Authorization: 
000150: 41 57 53 20 41 4b 49 41 00 00 00 00 00 00 00 00  AWS AKIAxxxxxxxx
000160: 00 00 00 00 00 00 00 00 3a 65 38 36 4e 79 70 59  xxxxxxxx:e86NypY
000170: 73 6b 6b 2f 52 4b 4d 6b 45 50 46 38 38 34 79 32  skk/RKMkEPF884y2
000180: 55 6a 4d 73 3d 0d 0a 0d 0a                       UjMs=....

Immediately following in the upstream is the XML document passed as the POST data. The XML document is valid XML, checked using an online XML verifier:

000000: 3c 44 65 6c 65 74 65 3e 3c 51 75 69 65 74 3e 74  <Delete><Quiet>t
000010: 72 75 65 3c 2f 51 75 69 65 74 3e 3c 4f 62 6a 65  rue</Quiet><Obje
000020: 63 74 3e 3c 4b 65 79 3e 2f 77 77 77 2d 68 79 70  ct><Key>/www-hyp
[lines deleted]
003bf0: 25 44 37 25 39 34 2f 61 5b 70 6c 75 73 5d 25 44  %D7%94/a[plus]%D
003c00: 37 25 39 31 5b 70 6c 75 73 5d 63 5b 70 6c 75 73  7%91[plus]c[plus
003c10: 5d 25 44 37 25 39 33 2e 70 6e 67 3c 2f 4b 65 79  ]%D7%93.png</Key
003c20: 3e 3c 2f 4f 62 6a 65 63 74 3e 3c 2f 44 65 6c 65  ></Object></Dele
003c30: 74 65 3e                                         te>

Here are the responses from the server:

000000: 75 70 6c 6f 61 64 20 63 6f 6d 70 6c 65 74 65 6c  upload completel
000010: 79 20 73 65 6e 74 20 6f 66 66 3a 20 31 35 34 31  y sent off: 1541
000020: 31 20 6f 75 74 20 6f 66 20 31 35 34 31 31 20 62  1 out of 15411 b
000030: 79 74 65 73 0a                                   ytes.

000000: 48 54 54 50 2f 31 2e 31 20 34 30 30 20 42 61 64  HTTP/1.1 400 Bad
000010: 20 52 65 71 75 65 73 74 0d 0a                     Request..

000000: 78 2d 61 6d 7a 2d 72 65 71 75 65 73 74 2d 69 64  x-amz-request-id
000010: 3a 20 46 34 32 41 36 38 45 37 46 30 37 33 32 42  : F42A68E7F0732B
000020: 39 32 0d 0a                                      92..

000000: 78 2d 61 6d 7a 2d 69 64 2d 32 3a 20 33 4c 30 54  x-amz-id-2: 3L0T
000010: 35 4c 6d 4f 59 56 4c 68 67 62 74 44 30 79 4d 56  5LmOYVLhgbtD0yMV
000020: 49 73 59 52 6d 39 4f 51 58 50 71 67 77 6d 6a 39  IsYRm9OQXPqgwmj9
000030: 64 4a 34 42 51 75 2f 37 31 59 70 36 76 61 57 57  dJ4BQu/71Yp6vaWW
000040: 78 57 2b 73 69 4c 4a 51 58 51 4f 30 45 67 63 79  xW+siLJQXQO0Egcy
000050: 4b 36 64 76 32 31 41 3d 0d 0a                    K6dv21A=..

000000: 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70  Content-Type: ap
000010: 70 6c 69 63 61 74 69 6f 6e 2f 78 6d 6c 0d 0a     plication/xml..

000000: 54 72 61 6e 73 66 65 72 2d 45 6e 63 6f 64 69 6e  Transfer-Encodin
000010: 67 3a 20 63 68 75 6e 6b 65 64 0d 0a              g: chunked..

000000: 44 61 74 65 3a 20 53 75 6e 2c 20 32 31 20 46 65  Date: Sun, 21 Fe
000010: 62 20 32 30 31 36 20 31 36 3a 32 30 3a 30 34 20  b 2016 16:20:04 
000020: 47 4d 54 0d 0a                                   GMT..

000000: 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 63 6c 6f 73  Connection: clos
000010: 65 0d 0a                                         e..

000000: 53 65 72 76 65 72 3a 20 41 6d 61 7a 6f 6e 53 33  Server: AmazonS3
000010: 0d 0a                                            ..

000000: 0d 0a                                            ..

000000: 31 30 36 0d 0a 3c 3f 78 6d 6c 20 76 65 72 73 69  106..<?xml versi
000010: 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e  on="1.0" encodin
000020: 67 3d 22 55 54 46 2d 38 22 3f 3e 0a 3c 45 72 72  g="UTF-8"?>.<Err
000030: 6f 72 3e 3c 43 6f 64 65 3e 4d 69 73 73 69 6e 67  or><Code>Missing
000040: 52 65 71 75 65 73 74 42 6f 64 79 45 72 72 6f 72  RequestBodyError
000050: 3c 2f 43 6f 64 65 3e 3c 4d 65 73 73 61 67 65 3e  </Code><Message>
000060: 52 65 71 75 65 73 74 20 42 6f 64 79 20 69 73 20  Request Body is 
000070: 65 6d 70 74 79 3c 2f 4d 65 73 73 61 67 65 3e 3c  empty</Message><
000080: 52 65 71 75 65 73 74 49 64 3e 46 34 32 41 36 38  RequestId>F42A68
000090: 45 37 46 30 37 33 32 42 39 32 3c 2f 52 65 71 75  E7F0732B92</Requ
0000a0: 65 73 74 49 64 3e 3c 48 6f 73 74 49 64 3e 33 4c  estId><HostId>3L
0000b0: 30 54 35 4c 6d 4f 59 56 4c 68 67 62 74 44 30 79  0T5LmOYVLhgbtD0y
0000c0: 4d 56 49 73 59 52 6d 39 4f 51 58 50 71 67 77 6d  MVIsYRm9OQXPqgwm
0000d0: 6a 39 64 4a 34 42 51 75 2f 37 31 59 70 36 76 61  j9dJ4BQu/71Yp6va
0000e0: 57 57 78 57 2b 73 69 4c 4a 51 58 51 4f 30 45 67  WWxW+siLJQXQO0Eg
0000f0: 63 79 4b 36 64 76 32 31 41 3d 3c 2f 48 6f 73 74  cyK6dv21A=</Host
000100: 49 64 3e 3c 2f 45 72 72 6f 72 3e 0d 0a 30 0d 0a  Id></Error>..0..
000110: 0d 0a                                            ..

As far as I can see, there is an XML document sent as the POST data. what is S3 complaining about?

Thanks in advance!

Upvotes: 0

Views: 1181

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179064

I don't think S3 actually believes the XML document to be empty -- I think it believes the request body is generally unusable and the error message it returns is a little bit imprecise. Here's the issue:

000110: 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70  Content-Type: ap
000120: 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d  plication/x-www-
000130: 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d  form-urlencoded.

Your request body is not actually encoded as application/x-www-form-urlencoded so this Content-Type: request header you're sending isn't correct.

The example in the API documentation for multi-object-delete shows no Content-Type: request header at all, though something more valid like application/xml would probably work, too, if your HTTP library makes it difficult to not send the header at all.

I can really only speculate why the error is a little bit imprecise, but it seems as if a front-end request parsing subsystem at S3 is probably discarding the body since it's not actually encoded as the request header says it is. It ends up with something it can't properly parse, and therefore nothing usable, and ultimately reports that the expected body was "missing."

Upvotes: 2

Related Questions