refactor: centralize URL fetching with host validation and default timeouts - #14
Open
anurag6569201 wants to merge 1 commit into
Conversation
…meouts Source PR: Unstructured-IO#4388 Source head: e78efde
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
unstructured/safe_http.pyas a single, shared entry point foroutbound URL fetches, and routes the
url=code paths inpartition,partition_html, andpartition_mdthrough it. Previously each of thesecalled
requests.getdirectly with inconsistent (and in some cases absent)timeout and validation behavior; this centralizes that logic in one place so
it stays consistent and testable.
What changed
unstructured/safe_http.py— asafe_get()helper that all threepartitioners now use instead of calling
requests.getdirectly.http/httpsscheme allowlistvalidated is the address actually connected to
credential material (
Authorization/Cookie/proxy auth, plusauth=/cookies=) on cross-origin hops via requests' ownshould_strip_auth(connect, read)timeouts, and refusal of proxied requestsallow_private=/ theUNSTRUCTURED_ALLOW_PRIVATE_URLenvironment variable for controlled local usage
Behavior changes (why this is a minor release)
Fetches that resolve to non-routable, loopback, or link-local addresses are
now rejected by default. Outbound fetches also now carry default timeouts
where some previously had none. Callers that legitimately need to reach a
private/internal host can opt out with
UNSTRUCTURED_ALLOW_PRIVATE_URL=1(orallow_private=True).Tests
Adds
test_unstructured/test_safe_http.pycovering IP/hostnameclassification, connect-time validation, redirect re-validation, cross-origin
credential stripping, and the opt-out.
Version
Bumps to
0.24.0(see CHANGELOG) — minor, reflecting the behavior changesabove.
Source merge-base:
f6eea758911fcf627cbe6f9df9f790e549500d7bSource head:
e78efdeda52584c1bea6e6b4b10b901520f28f8f