sabre-io / dav

sabre/dav is a CalDAV, CardDAV and WebDAV framework for PHP
http://sabre.io
BSD 3-Clause "New" or "Revised" License
1.53k stars 346 forks source link

HTTP 500 while posting event with wrong content-type #1004

Open brunt82 opened 7 years ago

brunt82 commented 7 years ago

When I POST an event with the wrong content-type ("text/xml" instead of "text/calendar"), I receive HTTP error 500 and a "LibXMLException"-exception:

POST http://baikal0603.example.com:8080/calendars/groupware-test1@example.com/inbox
Content-Type: text/xml; charset=utf-8
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example Corp.//CalDAV Client//EN
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20040901T200200Z
ORGANIZER:mailto:lisa@example.com
DTSTART:20040902T130000Z
DTEND:20040902T140000Z
SUMMARY:Design meeting
UID:34222-232@example.com
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR;CUTYPE=IND
 IVIDUAL;CN=Lisa Dusseault:mailto:lisa@example.c
 om
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;ROLE=RE
 Q-PARTICIPANT;CUTYPE=INDIVIDUAL;CN=Bernard Desr
 uisseaux:mailto:bernard@example.com
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;ROLE=RE
 Q-PARTICIPANT;CUTYPE=INDIVIDUAL;CN=Cyrus Daboo:
 mailto:cyrus@example.com
END:VEVENT
END:VCALENDAR

Response:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:sabredav-version>3.2.2</s:sabredav-version>
  <s:exception>Sabre\Xml\LibXMLException</s:exception>
  <s:message>Document is empty
 on line 1, column 1</s:message>
</d:error>
DeepDiver1975 commented 7 years ago

When I POST an event with the wrong content-type ("text/xml" instead of "text/calendar"), I

this is absolutly correct behavior form my pov. your content type ix text/xml but you are not transmitting xml in the body.

works as designed -> close

brunt82 commented 7 years ago

I'm sorry, but this seems not to be correct. When the content type does not reflects the request body, it is clearly an error by the client. Therefore the server must send a HTTP error code 4xx (in this case I would prefer 400). HTTP 500 leads to an server error, which is not the case here:

See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes