erlyaws / yaws

Yaws webserver
https://erlyaws.github.io
BSD 3-Clause "New" or "Revised" License
1.28k stars 267 forks source link

Can not return {header, {accept_ranges, "bytes"}} #352

Closed leoliu closed 5 years ago

leoliu commented 5 years ago

Returning {header, {accept_ranges, "bytes"}} from out/1 causes a crash:

Yaws process died: {function_clause,
                       [{yaws,accumulate_header,
                            [{accept_ranges,"bytes"}],
                            [{file,"yaws.erl"},{line,1916}]},
                        {yaws_server,deepforeach,2,
                            [{file,"yaws_server.erl"},{line,1429}]},
                        {yaws_server,handle_ut,4,
                            [{file,"yaws_server.erl"},{line,2295}]},
                        {yaws_server,handle_method_result,7,
                            [{file,"yaws_server.erl"},{line,1408}]},
                        {yaws_server,acceptor0,2,
                            [{file,"yaws_server.erl"},{line,1074}]},
                        {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,249}]}]}
vinoski commented 5 years ago

The accept_ranges header is not documented as a header that Yaws treats specially, so you must specify it as a string, not an atom:

{header, {"Accept-Ranges", "bytes"}}

See the yaws_api(5) man page or the yaws pdf documentation, section 7.6 for a list of headers for which Yaws allows atom names.

leoliu commented 5 years ago

accept_ranges appears in #headers but not #outh in yaws.hrl.

vinoski commented 5 years ago

Correct, which is why it'll work fine if you specify it as a string. And even if I add it to #outh, specifying it as a string will still work.

leoliu commented 5 years ago

But it is a bit confusing though where you can specify the atom accept_range when reading but not when writing the header.

leoliu commented 5 years ago

Thanks, @vinoski.

leoliu commented 5 years ago

Hi @vinoski

I just discovered something unusual after the change. The following no longer outputs the accept-ranges header. But if I revert to 576ba9c5dd7233ee061a85245475c90edf332378 it works again.

{page, {[{header, {"Accept-Ranges", <<"bytes">>}}], Page}}
vinoski commented 5 years ago

Thanks, this was my mistake. Fixed on master now, and with a new unit test.

leoliu commented 5 years ago

Thanks for the fix.