OpenRasta http options method support

87 views
Skip to first unread message

Konstantin Nosov

unread,
Sep 28, 2012, 3:47:14 AM9/28/12
to openevery...@googlegroups.com
I'm using backbone accessing REST api implemented with openrasta. Backbone sends HTTP OPTIONS request before sending PUT request to create object(suppose due to cross domain), and gets 405 Method Not Allowed.
I have a feeling that OR should serve such requests following from it's configuration, and 405 is result of error in my OR configuration, is it so or I neeed to handle HTTP OPTIONS explicitly?

request sample:

  1. Request Method:
    OPTIONS
  2. Status Code:
    405 Method Not Allowed
  3. Request Headersview source
    1. Accept:
      */*
    2. Accept-Charset:
      ISO-8859-1,utf-8;q=0.7,*;q=0.3
    3. Accept-Encoding:
      gzip,deflate,sdch
    4. Accept-Language:
      en-US,en;q=0.8
    5. Access-Control-Request-Headers:
      origin, content-type, accept
    6. Access-Control-Request-Method:
      PUT
    7. Connection:
      keep-alive
    8. Host:
    9. Origin:
    10. Referer:
    11. User-Agent:
      Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
  4. Response Headersview source
    1. Access-Control-Allow-Origin:
      *
    2. Content-Length:
      0
    3. Date:
      Thu, 27 Sep 2012 11:23:29 GMT
    4. Server:
      Microsoft-HTTPAPI/2.0

Konstantin Nosov

unread,
Sep 28, 2012, 1:10:26 PM9/28/12
to openevery...@googlegroups.com
I've added following PipelineConributor to fixthe problem:

    public class CrossDomainPipelineContributor : IPipelineContributor 
    {
        public void Initialize(IPipeline pipelineRunner)
        {
            pipelineRunner.Notify(processOptions).Before<KnownStages.IUriMatching>();
        }
        private PipelineContinuation processOptions(ICommunicationContext context)
        {
            addHeaders(context);
            if (context.Request.HttpMethod == "OPTIONS")
            {
                context.Response.StatusCode = 200;
                context.OperationResult = new OperationResult.NoContent();
                return PipelineContinuation.RenderNow;
            }
            return PipelineContinuation.Continue;
        }
        private void addHeaders(ICommunicationContext context)
        {
            context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            context.Response.Headers.Add("Access-Control-Allow-Methods","POST, GET, OPTIONS, PUT, DELETE");
            context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
        }
    }
Reply all
Reply to author
Forward
0 new messages