This approach looks correct to me. The only other thing I'd do is add an assertion that 'origin_parsed.netloc' is not empty - there are some edge cases that can confuse urlparse, and I'd prefer to categorically avoid them.
This approach looks correct to me. The only other thing I'd do is add an assertion that 'origin_ parsed. netloc' is not empty - there are some edge cases that can confuse urlparse, and I'd prefer to categorically avoid them.