Repository navigation
Extract the article from html the client sends - #122
Merged
Merged
Conversation
A page behind a login or a paywall can't be extracted: readability fetches it as an anonymous visitor and gets the sign-in page or a teaser. A client that already has the page, such as the reader's browser, can now send it. POST /api/extract-html takes the URL and the html and extracts the article from that html with the rule for the URL's domain, without fetching the page. A page larger than 16 MiB is refused, and the request body is kept out of the request log, since the page may be one only its reader can see.
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.
Previously, readability could extract only the pages it fetched itself, as an anonymous visitor. A page behind a login or a paywall, such as a paid newsletter post, came back as its sign-in page or teaser.
After this change,
POST /api/extract-htmltakes{"url": ..., "html": ...}and extracts the article from the supplied html with the rule for the URL's domain, without fetching the page. A Reddit post page goes through the same Reddit converter as a fetched one, so it keeps its comments. The html is taken as UTF-8.UReadability.ExtractHTMLdoes the extraction and refuses a URL that is not an absolute http or https URL with a host. A page larger than 16 MiB is refused with 413. The request logger keeps logging request bodies on the other routes but not on this one, since the page may be one only its reader can see. Pictures are still downloaded from their URLs to choose the lead image.The route is meant for ukeeper-worker, which can then extract the page a reader's browser shows, including pages behind a login.
TestExtractHTMLandTestServer_ExtractHTMLcover the extraction against the same page fetched, the domain rule, a Reddit post page, URL validation, the size limit and the logging; each check fails when its part of the change is reverted.go test -race ./...andgolangci-lint runpass.