rawhat / mist

gleam HTTP server. because it glistens on a web
Apache License 2.0
260 stars 11 forks source link

Fails to process 'patch' methods and crashes #6

Closed mikeyjones closed 2 years ago

mikeyjones commented 2 years ago

Hi Rawhat,

I hit an issue when I set the HTTP method to PATCH, Mist crashes, with this error:

Error in process <0.164.0> with exit value:
{badarg,[{erlang,atom_to_binary,
                 [<<"PATCH">>,utf8],
                 [{error_info,#{module => erl_erts_errors}}]},
         {gleam_erlang_ffi,atom_to_string,1,
                           [{file,"build/dev/erlang/gleam_erlang/build/gleam_erlang_ffi.erl"},
                            {line,40}]},
         {mist@http,parse_request,2,
                    [{file,"build/dev/erlang/mist/build/mist@http.erl"},
                     {line,153}]},
         {mist@http,'-handler_func/1-fun-4-',3,
                    [{file,"build/dev/erlang/mist/build/mist@http.erl"},
                     {line,291}]},
         {glisten@tcp,'-start_handler/3-fun-0-',4,
                      [{file,"build/dev/erlang/glisten/build/glisten@tcp.erl"},
                       {line,231}]},
         {gleam@otp@actor,loop,1,
                          [{file,"build/dev/erlang/gleam_otp/build/gleam@otp@actor.erl"},
                           {line,92}]}]}

It looks like it's happening in http.gleam on line 124 when it calls |> atom.to_string. To me it seems like it's expecting an Atom but is getting passed a bitstring, although I am very new to Erlang so the errors do not make massive sense to me yet. I tried these other HTTP verbs Get,Post, Put, Delete and those all work fine, I haven't tried header, option etc.. yet.

Let me know if I can help to identify the issue and fix.

rawhat commented 2 years ago

Thanks for the detailed issue! Just pushed up a change to fix this. I'll need to check on what arbitrary method handling should look like (and CONNECT has some different behavior). But at least PATCH should be working now.