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

suggestions for API additions #1

Open
geoffbeier opened this issue Jul 29, 2020 · 0 comments
Open

suggestions for API additions #1

geoffbeier opened this issue Jul 29, 2020 · 0 comments

Comments

@geoffbeier
Copy link

Thanks for making this! I needed a quick tool to manipulate HTTP POST requests I had logged in Charles, and this was quite helpful.

When I used it, I needed to make a few changes. The first two are probably no-brainers to add, and I only wanted them to keep knowledge about the JSON structure from leaking out into my tool.

On the CharlesRequest class, I added

    def get_headers(self):
        return self.request_dict['request']['header']['headers']

    def get_body(self):
        return self.request_dict['request']['body']['text']

The other thing I needed was to build a session from a file-like object. I'm not sure I've thought that through carefully enough that you'll want to add it just the way I did, but here's how I changed the CharlesSession constructor:

    def __init__(self, request_list=list(), path=None, file=None):
        if file is not None:
            self._all_requests = [CharlesRequest(r) for r in json.load(file)]
        elif len(request_list) == 0 and path is not None:
            with open(path, 'r') as f:
                self._all_requests = [CharlesRequest(r) for r in json.load(f)]
        elif len(request_list) > 0 and path is None:
            self._all_requests = [CharlesRequest(r) for r in request_list]
        else:
            self.fail('only one initialization parameter should be specified')
        _assign_indexes(self._all_requests)

All my mods and my little tool are all available in my public repo under the same license as pycharles in case you find it interesting or useful.

I haven't used this enough and thought it through carefully enough to make it a pull request (and probably won't end up doing so) but it seemed worth sharing anyway.

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

No branches or pull requests

1 participant