Skip to content
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

RFC: Switch from #req{} to maps #54

Closed
wants to merge 3 commits into from
Closed

RFC: Switch from #req{} to maps #54

wants to merge 3 commits into from

Conversation

yurrriq
Copy link
Member

@yurrriq yurrriq commented May 5, 2018

This is based on #53 and was fairly mechanical after that. Notably, it drops elli_request:is_request/1, which, according to a quick GitHub search, no one was really using anyway.

If we want to go this route, we'll probably want to add some more safeguards and/or default values. One approach can be seen in elli_request:to_proplist/1.

yurrriq added 3 commits May 5, 2018 16:07
Also, add more specs and breathing room here and there.
Also drop elli_request:is_request/1.
-spec version(elli:req()) -> elli_http:version().
version(#req{version = Version}) -> Version.
-spec version(elli:req()) -> elli_http:version().
version(Req) -> maps:get(version, Req, undefined).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hackish workaround for the chunked_ref test in elli_tests that's expected to return {error, not_supported}, due the missing version. A better approach might be to update the test with #{version => Version} where Version =/= {1, 1}.

args => [],
socket => undefined
},
maps:to_list(maps:merge(Defaults, Req)).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how I feel about this. Is there a better way to provide defaults values for maps? We probably want to do this other places too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't, except if always using maps:get with a default.

Part of why it may be better to stick with a record. I'm undecided on this. Are there specific benefits to using a map for req?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can think of, except that it'd be easier to do ad hoc extensions à la Ring then.

@coveralls
Copy link

coveralls commented May 5, 2018

Coverage Status

Coverage increased (+0.4%) to 75.941% when pulling 1511d55 on feature/req-maps into e58a099 on develop.

@@ -27,7 +27,20 @@
-export_type([req/0, http_method/0, body/0, headers/0, response_code/0]).

%% @type req(). A record representing an HTTP request.
-type req() :: #req{}.
-type req() :: #{method => elli:http_method(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems wrong to have all of these being optional? I assume some are required and should be like method := elli:http_method()?

@lpil
Copy link
Contributor

lpil commented Nov 10, 2018

What's the rational for this? Are there benchmarks to see how this may alter performance?

@yurrriq
Copy link
Member Author

yurrriq commented Nov 12, 2018

There's no particular rationale. And we don't have any such benchmarks. It's more of partial implementation of a half-baked idea. Since no one, myself include, seems particularly supportive or enthusiastic, let's table it.

@yurrriq yurrriq closed this Nov 12, 2018
@yurrriq yurrriq mentioned this pull request Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants