-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples #38
Examples #38
Conversation
…ne API simular examples that solve the same tasks. Demo examples are provided with instructions that will help you navigate their functionality.
file(DirName, FileName) -> | ||
{ok, CurrentDir} = file:get_cwd(), | ||
ParentDir = filename:join([CurrentDir, DirName]), | ||
filename:join([ParentDir, FileName]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to add here something like mochiweb_util:safe_relative_path/1
- just as an example that we need to be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. In OTP app all works just fine.
It is necessary be safe (checking for the existence of a file) in any way.
In the developed examples, I offer several options (types of projects (escript and OTP app way)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we just add a comment here to warn the user to sanitize the path before concatenation the file name to the directory. Then it is up to the programmer taking inspiration from this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment about it would be enough. filename:join make a lot of sanitizing.
examples/upload/src/controller.erl
Outdated
|
||
process(<<"GET">>, _ContentType, _Accepted, Context) -> | ||
{true, Context}; | ||
process(<<"POST">>, _ContentType, _Accepted, Context) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we have something the wrong way around in another example, or piece of code.
The arguments of process/4 are
process(_Method, AcceptedCT, ProvidedCT, Context)
Where AcceptedCT is the content-type of the incoming payload, and ProvidedCT is the content-type of the response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not expect that this parameter is so useful.
examples/upload/src/controller.erl
Outdated
process(<<"GET">>, _ContentType, _Accepted, Context) -> | ||
{true, Context}; | ||
process(<<"POST">>, _ContentType, _Accepted, Context) -> | ||
case cowmachine_req:resp_content_type(Context) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to get the content-type of the payload here, which is the AcceptedCT.
This is the same as the AcceptedCT
in the process/4
parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mworrell for describing this. I have added this simplification.
Thanks! This will be very helpful to new people, and as a general documentation. |
I am glad to add some improvements to Cowmachine project.
cowboy_options(Dispatch) ->
|
Add rebar3 implementation of Cowboy Web Server examples plus Cowmachine API simular examples that solve the same tasks.
There are rebar3 (Escript, OTP) applications which demonstrate how to use Cowmachine API.
controller_fuctions
demonstrates controller with default Controller API functions.hello_world
is simple demo.hello_world_chunked
demonstrates chunked data transfer with two one-second delays.hello_world_rest
demonstrates returning the data type that matches the request type (html, text, json).hello_world_ssl
demonstrates simplest SSL application.echo_get
GET parameter echo.echo_post
POST parameter echo.websocket
WebSocket example.websocket2
WebSocket example (another way).compress_response
checks response compression support.cookie
how to work with cookie example.eventsource
how to work EventSource JS API and server-sent events.file_server
file server implementation.markdown_middleware
generate markdown file from html.upload
multipart upload.rest_basic_auth
authentication implementation.Add a EUnit test.
Fix rebar.config typo.
Fix img absence of Zotonic logo for ExDoc documentation generation.
Demo examples are provided with instructions that will help you navigate their functionality. Demo examples are provided with instructions that will help you navigate their functionality.