3

you all might know that browsers do preflighted HTTP requests in some cases: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests

My web application is still on Symfony1. I want to implement a RESTful service and therefore using Symfony routing to allow specific HTTP request methods like GET or POST (http://symfony.com/legacy/doc/reference/1_4/en/10-Routing#chapter_10_sub_sf_method).

Example:

login:
  url:   /v1/login
  class: sfRequestRoute
  param: { module: rest, action: login }
  requirements:
    sf_method: [post, put, delete]
    #sf_method: [options] NOT WORKING

It seems to me that OPTIONS requests cannot be defined/handled as sf_method value. Because I couldn't find any information if my idea is right, I'm wondering if I'm right or maybe there is a solution I couldn't find, too.

Thanks in advance!

1 Answers1

1

Sorry to revive this old question but I found a solution. I ran into the same issue and I added the request method OPTIONS to the allowed methods in lib/sfRequest.class.php and lib/sfWebRequest.class.php You can check the latest commit here to see the differences: 6ad018c

Since I cannot update the original Symfony1 GitHub repository, I created a copy with additional fixes needed due to the various PHP upgrades. This fixes the PHP deprecated warnings due to use of the /e modifier in preg_replace calls as well.
Note that this still doesn't make Symfony1 PHP7 compatible. I'm running this successfully with PHP 5.6.30

The repository is https://github.com/diem-project/symfony.git

Background: Diem uses Symfony1 (1.4.20), hence the GitHub organisation diem-project

4levels
  • 3,134
  • 1
  • 23
  • 22