[erlang-patches] Patch for packet_parser.c to Include HTTP Methods Defined in RFC 2518 / WebDAV

Oscar Hellström <>
Mon Feb 16 13:08:17 CET 2009


Hi,

Jan Lehnardt wrote:
> Hi Oscar,
>
> thanks for your comments.
<snip>
> I wouldn't mind atoms or strings either, what's weird is that the API
> returns both and clients have to deal with whether they use RFC 2616-
> defined methods or not. Either asking explicitly for WebDAV methods
> using `inet:setopts(Socket, [{packet, webdav}])` or just handling all
> known HTTP extension methods as atoms (for backwards compatibility),
> "fixes" that.
>
> The reasoning behind the patch is less code (less code is good), not
> speed.

I agree, but since you still have to check if you got another method,
i.e. when is_atom(Method), you're just postponing the problem. Making
all methods atoms isn't possible due to DOS attacks and I'm sure that
there are a few other RFCs, more or less well known, that will add other
HTTP methods. For instance, an HTTP proxy might wan to implement the
CONNECT method... My approach is letting the receiving port of the code
transform all methods to strings before actually dealing with the request.

<snip>
> My version of `handle_extension_method()` reads:
>
> handle_extension_method("PROPFIND", CliSock, Req, Head) ->
>     'PROPFIND'(CliSock, Req, Head);
> handle_extension_method("MKCOL", CliSock, Req, Head) ->
>     'MKCOL'(CliSock, Req, Head);
> handle_extension_method("MOVE", CliSock, Req, Head) ->
>     'MOVE'(CliSock, Req, Head);
> handle_extension_method("COPY", CliSock, Req, Head) ->
>     'COPY'(CliSock, Req, Head);
> handle_extension_method(_Method, CliSock, Req, Head) ->
>     not_implemented(CliSock, Req, Head).
>
> It gets called from:
>
> call_method(Method, CliSock, Req, H) ->
>     case Method of
>         F when atom(F) ->
>             ?MODULE:F(CliSock, Req, H);
>         L when list(L) ->
>             handle_extension_method(L, CliSock, Req, H)
>     end.
>
> I.e. "METHOD" is routed through `handle_extension_method()`
> to call `'METHOD'()` in `call_method()` while 'METHOD' directly
> calls `'METHOD'()`.
>
> Again, Yaws 1.79.
>
> So earlier versions of YAWS break.
My bad, I think mine reads the same ;)

Cheers

-- 
Oscar Hellström, 
Office: +44 20 7655 0337
Mobile: +44 798 45 44 773
Erlang Training and Consulting
http://www.erlang-consulting.com/




More information about the erlang-patches mailing list