u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
448 stars 144 forks source link

Defaults to http/1.0, which is being deprecated #273

Closed khalwat closed 3 years ago

khalwat commented 3 years ago

First, thanks for this library, I've been using it for some time to pull down .ics files from https://trello.com and parse them, it's been great!

Recently, however, it started failing with:

file(https://trello.com/calendar/58818099de7afeb3eccf53c3/596c082de8b3646b91fe224c/a33556c5da5218fe3ed14f368b6b77bc.ics): failed to open stream: HTTP request failed! HTTP/1.1 426 Upgrade Required

So it looks like Trello is phasing out their use of http/1.0, as I would assume many sites are, given that http/1.1 was released in 1999.

Having a look at the code, I found that remote .ics files are being downloaded with stream_context_create() -- unfortunately, the protocol_version is set to 1.0 by default.

I can fix this by adding this to the fileOrUrl() method:

        $options['http']['protocol_version'] = '1.1';
        array_push($options['http']['header'], 'Connection: close');

and it seems like a sane default to me... but perhaps also to mitigate issues like this, an optional header array could be passed in to use as well?

Happy to PR it in, lmk!

khalwat commented 3 years ago

PR added: https://github.com/u01jmg3/ics-parser/pull/274