Skip to content

Conversation

@andymillersj
Copy link

I wanted to perform a string substitution that could be more dynamic than what was already supported, so I added support for using lambda functions as replacement arguments.

While implementing my changes, I also made a slight modification to encode_content to better handle content passed to it and removed the mitmproxy net import since it is not necessary since this commit.

moxy.py Outdated
if index != -1:
replace_lambda_value = lambda_with_args(replace_lambda_value, index)
try:
code_object = compile(replace_lambda_value, "<lambda>", "eval")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if these compiled lambdas should be cached like compiled regexes are? Also, several lines of duplicated code between replace_lambda_in_dict and replace_lambda_in_content, maybe move to a function called by both?

Copy link
Author

Choose a reason for hiding this comment

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

Great feedback, I will refactor accordingly.

moxy.py Outdated
try:
with open(content, "rb") as content_file:
if content.endswith("html"):
if content.endswith(".html"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The lack of . was actually intentional to cover xhtml, shtml and such variants, but TBH probably not much of an issue in practice, and xhtml might need its own type anyway

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the context; I'll go ahead and revert this.

@andymillersj andymillersj requested a review from arkku February 2, 2021 16:56
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.

2 participants