-
Notifications
You must be signed in to change notification settings - Fork 17
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
A collection of general API improvements #36
Conversation
@bitwalker the 3rd change needs more discussion. |
@secretworry There are a couple of reasons for why I disagree that this is necessary:
I don't think there is any good reason why it needs to remain, the same use case can be supported far more cleanly elsewhere. |
49a8bc6
to
1924595
Compare
@secretworry I've updated the PR to include a new |
- Working with Conn APIs requires calling new/0 or new/1 first old APIs are deprecated - new/1 parses the provided string with URI.parse/1 and sets the Conn struct fields accordingly (so you can pass full or partial url fragments and get what you would expect, including those containing query strings) - All headers are normalized to lower-case on put/get, and internally headers are a simple key/value map instead of the previous key => key/value map, which was unnecessary. - Implemented get_req_headers/1, deprecated get_req_header/1 - Implemented put_req_headers/2, deprecated put_req_header/2 - get_req_header/2 returns String.t instead of {String.t, String.t} - get_req_headers/1 returns %{String.t => String.t} instead of %{String.t => %{String.t => String.t}} - Added a number of typespecs, and fixed invalid ones - Some small style fixes, documentation updates - Fixed a bug with the Header middleware which was not overriding headers in the connection if already set. This one may be up for discussion if what's really desired. - Added HeaderCase middleware for enforcing header casing
2a0ebd4
to
1c24b88
Compare
extra_headers | ||
|> Enum.reduce(headers, fn {header_name, header_value}, acc -> | ||
acc | ||
|> Map.delete(header_name) |
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.
why need delete header_name first?
It's seems to have guaranteed that the head is all lowercase.
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.
After thinking about it some more, I agree that this is unnecessary here, as it doesn't actually enforce what I intended which is to ensure there are never any duplicates. I'll update the PR
|
||
The following is a full implementation of a client showing various features of Maxwell. | ||
|
||
```elixir |
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.
Delete those, user can't find example:
how to send file/stream?
Maybe we need more example in adapter's document?
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'm actually planning on improving the docs around that, but I decided to hold off until this PR is merged. I think improving the adapter docs as well as having a more in depth description around streaming and files in the readme is preferable to a big example client which leaves out the details. I can make that part of the PR if you want, or after it's merged, your call.
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 docs can be updated after it's merged.
Thank you very much!
- Added more tests
1c24b88
to
51dcd96
Compare
The following is a list of the changes made. To me, the ergonomics of this improved API are much nicer, as it's simpler to work with Conn, and the APIs tend to return what you'd expect if you think of Conn as any other data structure.
old APIs are deprecated
struct fields accordingly (so you can pass full or partial url
fragments and get what you would expect, including those containing
query strings)
headers are a simple key/value map instead of the previous key =>
key/value map, which was unnecessary.
%{String.t => %{String.t => String.t}}
headers in the connection if already set. This one may be up for
discussion if what's really desired.
the wrong thing, and so tests were passing even though the code was broken.
I'm opening this as a PR rather than just making the changes because it's a large changeset and you may not approve, but I think these are important changes to make and will make Maxwell much nicer to work with. I'll be using my fork in the meantime for that reason.