[erlang-questions] cowboy etags problems

Nathaniel Waisbrot nathaniel@REDACTED
Mon Jan 16 21:39:54 CET 2017


Oh sorry, I misunderstood your question.

So what you want is to pass along the etags from your upstream, right? What sort of work is your code doing? Are you using Cowboy's REST flow? If your proxy server does some request validation and then passes the request along, maybe you want to do all the work in resource_exists (including sending the response) and return `{stop, Req, State}` from the callback to skip the rest of the handlers.



> On Jan 16, 2017, at 3:00 PM, HODGSON, GARRY <GH2787@REDACTED> wrote:
> 
> Thanks for your reply. I have, indeed, now told them their etags are wrong, showed them the rfc.
> It’s really more the if-match handling that’s a problem.
> 
> 
> On 1/16/17, 2:54 PM, "Nathaniel Waisbrot" <nathaniel@REDACTED> wrote:
> 
>    I agree that the quotes are surprising, but that's how that header works.
> 
>    Are you sure that you need to run with broken etags? I've used etags from Cowboy with all major browsers and it works correctly. If you've got a broken client you may want to consider fixing the client rather than breaking the server, because you'll just keep encountering surprises (for example, if your client is some home-brewed thing and then you start using a HTTP library that does etags correctly).
> 
>    But if you want the headers to work some other way, then it shouldn't be too hard. I'd just copy the Cowboy code and modify it as needed: https://github.com/ninenines/cowboy/blob/c5a9771ac4f7844b61b5e36bfc7eb371a082c560/src/cowboy_rest.erl#L673-L697
> 
> 
> 
>> On Jan 16, 2017, at 9:57 AM, Garry Hodgson <garryh@REDACTED> wrote:
>> 
>> I have an application that acts as an http proxy, accepting REST api calls, forwarding to appropriate endpoints, and returning result. It's built atop Cowboy, and generally works well.
>> 
>> However, while exploring a reported bug I discovered that I was not handling etags properly. Whenever an if-match header was included, Cowboy returned a 400, before my code ever saw the request. I eventually discovered that I was being sent headers like: If-Match: 1234567
>> 
>> Instead of: If-Match: "1234567"
>> 
>> Digging into the RFC it appears that Cowboy is handling this properly, as the surrounding quotes are part of the spec. But it will still cause problems for my users.
>> 
>> When I pass the correct If-Match header, I get a 412 Precondition Failed. This also appears to be correct behavior, as my Cowboy instance doesn't have the etag, the eventual endpoint should. So I think what I really need to do is to turn off If-Match handling in Cowboy and just pass through the headers I get, or possibly intercept the request before Cowboy looks at this and massage the inputs/outputs.
>> 
>> Am I correct in this diagnosis? Is there any way to solve this? It's kind of a showstopper.
>> 
>> Any insights appreciated.
>> 
>> Thanks
>> 
>> 
>> 
>> 
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
> 
> 
> 




More information about the erlang-questions mailing list