8000 #99 - add --resolve option · Pull Request #659 · httpie/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#99 - add --resolve option #659

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

Closed
wants to merge 2 commits into from
Closed

#99 - add --resolve option #659

wants to merge 2 commits into from

Conversation

ghost
Copy link
@ghost ghost commented Mar 1, 2018

Added --resolve option. Few points I'd like to get help with:

  • Would all requests happen within the context of the CustomResolver being created in the core.py:program?
  • What would be the best way to update README.rst?
  • I've tried to provide a support for IPv6 without square brackets, so something like --resolve example.org:::1,::2 would also work. Is that fine or square brackets syntax should be enforced so it would be mandatory to write something like --resolve example.org:[::1],[::2]?

@fearphage
Copy link
fearphage commented Mar 1, 2018

Fixes #99 /cc @aztlan2k

Copy link
@fearphage fearphage left a comment

Choose a reason for hiding this comment

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

I don't own the repo and can't merge, but I just had some suggestions.

self.entries = {}
for entry in resolve:
host, port_and_addresses = entry.split(':', 1)
if ':' in port_and_addresses:

Choose a reason for hiding this comment

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

This logic is not very clear. It could use some commenting I think.possibly to show possible examples.

# ho.st:1.2.3.4
if ...
  # ho.st:1.2.3.4:[::1]
  if ...

Copy link
Author

Choose a reason for hiding this comment

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

For this and the next comment, would something like:

    @staticmethod
    def parse_resolve_entry(entry):
        """
        :param entry:
        :return: host, port (or `None` if absent) and
        """
        host, port_and_addresses = entry.split(':', 1)
        try:
            # If port is not absent, e.g. 'example.org:80:127.0.0.1'
            port, addresses = port_and_addresses.split(':', 1)
            port = int(port)
        except ValueError:
            port = None
            addresses = port_and_addresses

        return host, port, [
            a[1:-1] if a.startswith('[') and a.endswith(']') else a
            for a in addresses.split(',')
        ]

    def __init__(self, resolve):
        """
        :param resolve: A list of HOST[:PORT]:ADDRESS[:ADDRESS]? records
        :type resolve: list[str]
        """
        self.entries = {
            (host, port): addresses
            for host, port, addresses in map(self.parse_resolve_entry, resolve)
        }

work to make the logic more clear?

Choose a reason for hiding this comment

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

There's no need/benefit to having this be a static method over a global function. Other than that, I think it makes sense.

Copy link
Author

Choose a reason for hiding this comment

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

Separate function is for splitting what's going inside of __init__ into actual parsing (the function itself) and the internal state of the object. Otherwise, __init__ is violating the principle of a single responsibility.

Choose a reason for hiding this comment

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

I was saying there is no need for parse_resolve_entry to be a stactic method. It can be a global function. That is what I was saying.

def _parse_resolve_entry(...):
  # ...

class CustomResolver:

Static methods are usually used as part of the interface to the class, but it's unexpected for anyone to be calling CustomResolver.parse_resolve_entry(...).

if address[:1] == '[' and address[-1:] == ']':
address = address[1:-1]
final_addresses.append(address)
self.entries[(host, port)] = final_addresses

Choose a reason for hiding this comment

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

self.entries[(host, port)] = list(map(
  lambda a: a[1:-1] if a[:1] == '[' and a[-1:] == ']' else a, 
  addresses.split(',')
))

class CustomResolver:
def __init__(self, resolve):
"""
:param resolve: A list of HOST[:PORT]:ADDRESS[:ADDRESS]? records

Choose a reason for hiding this comment

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

This comment is not very clear. It looks like there can possibly be 4 pieces from record.split(":").

Copy link
Author

Choose a reason for hiding this comment

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

Could you suggest a better message in order to show there could be one or more trailing address? Would :ADDRESS[:ADDRESS...] work?

Choose a reason for hiding this comment

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

Can you show me a real world example of this usage? I'm not sure I understand how it will look and function based on the code.

Copy link
Author

Choose a reason for hiding this comment

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

Sure. For example localhost:[::1],[::2],[::3] would resolve localhost into a list of addresses: ::1, ::2, ::3 which will make httpie to try to connect to all 3 of them one-by-one.

@ghost
Copy link
Author
ghost commented Nov 1, 2018

@jakubroztocil is there any chance to merge this? Let me know if anything needs to be improved!

@malford
Copy link
malford commented Dec 7, 2018

This functionality would be great to have working with httpie!

@danihodovic
Copy link

Any update in 2020?

@Almad
Copy link
Almad commented Feb 3, 2021

Thank you very much for the effort and for the proposed patch and sorry to leave you hanging for such a long time. The reason for it was our uncertainty about how to approach this feature.

After talking through the pros and cons, the strong preference here would be to fix the underlying issue in urllib3 (see urllib3/urllib3#1209 ). Monkeypatching often leads to unintended side-effects and interactions, especially when done on system libraries. HTTPie is used in wide variety of systems and configurations and we'd strongly prefer not to expose this risk.

That said, if we'll end up going down the monkeypatch route, we'll definitely take this as an inspiration.

Any help with work on the urllib3 patch is appreciated. Otherwise, we'll give it a try, but let's see how this ends up priority-wise against other features.

See #99 for more context.

Also, if you'd like to discuss more on how to approach this, feel free to join our Discord!

Again, thanks for the time and effort. It's really appreciated.

@Almad Almad closed this 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
0