You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Yaws receives large POSTs and PUTs they are split into several calls to your out handler in your appmod. To handle the request you end up implementing a state machine - something like:
out(#arg{state=undefined, clidata=Data} =A)
whenis_binary(Data) ->%% size of post < partial_post_sizeInitialState=init_state(),
finalize_upload(process_data(Data, InitialState), A);
out(#arg{state=undefined, clidata= {partial, Data}})
whenis_binary(Data) ->%% first piece of chunked uploadInitialState=init_state(),
{get_more, undefined, process_data(Data, InitialState)};
out(#arg{state=State, clidata= {partial, Data}})
whenis_binary(Data) ->%% a piece in a chunked upload, neither first nor last
{get_more, undefined, process_data(Data, State)};
out(#arg{state=State, clidata=Data} =A)
whenis_binary(Data) ->%% last piece of chunked uploadfinalize_upload(process_data(Data, State), A);
If you have several places in your code where you handle large POSTs and PUTs you end up copying around this state machine with some minor modifications of init_state, process_data and finalize_upload.
How are people in general handling this (not too worrying) code smell? When these four clause-groups occur too many times within the same project I usually end up making some parameterized function, like:
, which reduces the four clauses to one clause and allows some reuse of the state machine handling large uploads.
Is this in general how people handle this code smell or is there some other more conveniant handling of large POSTs and PUTs in the API that I have not noted yet?
The text was updated successfully, but these errors were encountered:
You'd probably be better off asking this in the Yaws mailing list, since more users will see it there than here, but I don't think you're missing any convenience functions, and I don't see anything wrong with the approach you're taking to reuse your functions.
When Yaws receives large POSTs and PUTs they are split into several calls to your out handler in your appmod. To handle the request you end up implementing a state machine - something like:
If you have several places in your code where you handle large POSTs and PUTs you end up copying around this state machine with some minor modifications of init_state, process_data and finalize_upload.
How are people in general handling this (not too worrying) code smell? When these four clause-groups occur too many times within the same project I usually end up making some parameterized function, like:
, which reduces the four clauses to one clause and allows some reuse of the state machine handling large uploads.
Is this in general how people handle this code smell or is there some other more conveniant handling of large POSTs and PUTs in the API that I have not noted yet?
The text was updated successfully, but these errors were encountered: