Title:
REST restPath attribute not supporting regex that defines restpath argument as optional
| View in TrackerStatus/Resolution/Reason: Closed/Duplicate/Duplicate
Reporter/Name(from Bugbase): Mosh Teitelbaum / Mosh Teitelbaum (Mosh Teitelbaum)
Created: 10/31/2016
Components: REST Services
Versions: 2016
Failure Type:
Found In Build/Fixed In Build: CF2016_Update3 /
Priority/Frequency: Major / All users will encounter
Locale/System: English / Windows 10 64 bit
Vote Count: 0
Problem Description:
Following up on Bug 4197164, in order to support CORS preflight requests, every endpoint in the API must define an OPTIONS handler. Some endpoints can include optional path parameters such as "/users" and "/users/123". ColdFusion's REST support includes the ability to use regular expressions in restPath definitions which should be able to handle this and, so as not to have to create separate OPTIONS handlers for both of these formats, I tried to do just that. Unfortunately, it is not working as expected.
Steps to Reproduce:
1) Create an endpoint such as:
<cfcomponent rest="true" restpath="/users" produces="application/json">
<cffunction name="corsPreflight" access="remote" returntype="void" httpMethod="OPTIONS" restPath="{id:.*}">
<cfargument name="id" type="string" required="false" restargsource="Path" />
<!--- Do CORS stuff here --->
</cffunction>
</cfcomponent>
2) Send an OPTIONS request to this endpoint such as "/accounts/123". This will succeed.
3) Send an OPTIONS request to this endpoint such as "/accounts". This should succeed but will fail.
Actual Result:
Expected Result:
Any Workarounds:
Create two separate OPTIONS handler functions, one accepting the rest path parameter and one not such as:
<cffunction name="corsPreflight" access="remote" returntype="void" httpMethod="OPTIONS">
</cffunction>
<cffunction name="corsPreflightWithId" access="remote" returntype="void" httpMethod="OPTIONS" restPath="{id:.*}">
</cffunction>
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 4197166
External Customer Info:
External Company:
External Customer Name: Mosh Teitelbaum
External Customer Email:
External Test Config: My Hardware and Environment details:
ColdFusion 2016 Enterprise
Windows Server 2012
Attachments:
Comments: