From 615ee009616f5970469c406f0f8c7a650029b6d8 Mon Sep 17 00:00:00 2001 From: "FiveFilters.org" Date: Wed, 25 Aug 2021 02:44:19 +0200 Subject: Include more ancestors in candidate scoring https://github.com/mozilla/readability/commit/3844d8f05b3f114e3df16c3bc3caf44e5ba52181 --- test/test-pages/002/expected.html | 68 ++++++++++----------------------------- 1 file changed, 17 insertions(+), 51 deletions(-) (limited to 'test/test-pages/002/expected.html') diff --git a/test/test-pages/002/expected.html b/test/test-pages/002/expected.html index 301628c..564f9a9 100644 --- a/test/test-pages/002/expected.html +++ b/test/test-pages/002/expected.html @@ -33,8 +33,7 @@

The most useful, high-level part of the Fetch API is the fetch() function. In its simplest form it takes a URL and returns a promise that resolves to the response. The response is captured as a Response object.

-
-
fetch("/data.json").then(function(res) {
+                        
fetch("/data.json").then(function(res) {
   // res instanceof Response == true.
   if (res.ok) {
     res.json().then(function(data) {
@@ -47,10 +46,8 @@
   console.log("Fetch failed!", e);
 });
-

Submitting some parameters, it would look like this:

-
-
fetch("http://www.example.org/submit.php", {
+            
fetch("http://www.example.org/submit.php", {
   method: "POST",
   headers: {
     "Content-Type": "application/x-www-form-urlencoded"
@@ -66,7 +63,6 @@
   alert("Error submitting form!");
 });
-

The fetch() function’s arguments are the same as those passed to the
@@ -84,28 +80,23 @@
supporting CORS rules and ensuring cookies aren’t readable by third parties.

The Headers interface is a simple multi-map of names to values:

-
-
var content = "Hello World";
+            
var content = "Hello World";
 var reqHeaders = new Headers();
 reqHeaders.append("Content-Type", "text/plain"
 reqHeaders.append("Content-Length", content.length.toString());
 reqHeaders.append("X-Custom-Header", "ProcessThisImmediately");
-

The same can be achieved by passing an array of arrays or a JS object literal
to the constructor:

-
-
reqHeaders = new Headers({
+            
reqHeaders = new Headers({
   "Content-Type": "text/plain",
   "Content-Length": content.length.toString(),
   "X-Custom-Header": "ProcessThisImmediately",
 });
-

The contents can be queried and retrieved:

-
-
console.log(reqHeaders.has("Content-Type")); // true
+            
console.log(reqHeaders.has("Content-Type")); // true
 console.log(reqHeaders.has("Set-Cookie")); // false
 reqHeaders.set("Content-Type", "text/html");
 reqHeaders.append("X-Custom-Header", "AnotherValue");
@@ -116,7 +107,6 @@ console.log(reqHeaders.getAll(delete("X-Custom-Header");
 console.log(reqHeaders.getAll("X-Custom-Header")); // []
-

Some of these operations are only useful in ServiceWorkers, but they provide
a much nicer API to Headers.

Since Headers can be sent in requests, or received in responses, and have @@ -143,15 +133,13 @@ console.log(reqHeaders.getAll(All of the Headers methods throw TypeError if name is not a valid HTTP Header name. The mutation operations will throw TypeError if there is an immutable guard. Otherwise they fail silently. For example:

-
-
var res = Response.error();
+            
var res = Response.error();
 try {
   res.headers.set("Origin", "http://mybank.com");
 } catch(e) {
   console.log("Cannot pretend to be a bank!");
 }
-

Request

@@ -160,29 +148,24 @@ console.log(reqHeaders.getAll(

The simplest Request is of course, just a URL, as you may do to GET a resource.

-
-
var req = new Request("/index.html");
+        
var req = new Request("/index.html");
 console.log(req.method); // "GET"
 console.log(req.url); // "http://example.com/index.html"
-

You may also pass a Request to the Request() constructor to create a copy.
(This is not the same as calling the clone() method, which is covered in
the “Reading bodies” section.).

-
-
var copy = new Request(req);
+        
var copy = new Request(req);
 console.log(copy.method); // "GET"
 console.log(copy.url); // "http://example.com/index.html"
-

Again, this form is probably only useful in ServiceWorkers.

The non-URL attributes of the Request can only be set by passing initial
values as a second argument to the constructor. This argument is a dictionary.

-
-
var uploadReq = new Request("/uploadImage", {
+        
var uploadReq = new Request("/uploadImage", {
   method: "POST",
   headers: {
     "Content-Type": "image/png",
@@ -190,7 +173,6 @@ console.log(copy.url);
   body: "image data"
 });
-

The Request’s mode is used to determine if cross-origin requests lead to valid responses, and which properties on the response are readable. Legal mode values are "same-origin", "no-cors" (default) @@ -199,15 +181,13 @@ console.log(copy.url); origin with this mode set, the result is simply an error. You could use this to ensure that
a request is always being made to your origin.

-
-
var arbitraryUrl = document.getElementById("url-input").value;
+            
var arbitraryUrl = document.getElementById("url-input").value;
 fetch(arbitraryUrl, { mode: "same-origin" }).then(function(res) {
   console.log("Response succeeded?", res.ok);
 }, function(e) {
   console.log("Please enter a same-origin URL!");
 });
-

The "no-cors" mode captures what the web platform does by default for scripts you import from CDNs, images hosted on other domains, and so on. First, it prevents the method from being anything other than “HEAD”, @@ -225,8 +205,7 @@ fetch(arbitraryUrl, { mode: headers is exposed in the Response, but the body is readable. For example, you could get a list of Flickr’s most interesting photos today like this:

-
-
var u = new URLSearchParams();
+            
var u = new URLSearchParams();
 u.append('method', 'flickr.interestingness.getList');
 u.append('api_key', '<insert api key here>');
 u.append('format', 'json');
@@ -245,15 +224,12 @@ apiCall.then(function(respon
   });
 });
-

You may not read out the “Date” header since Flickr does not allow it via
Access-Control-Expose-Headers.

-
-
response.headers.get("Date"); // null
+
response.headers.get("Date"); // null
-

The credentials enumeration determines if cookies for the other domain are
sent to cross-origin requests. This is similar to XHR’s withCredentials @@ -308,14 +284,12 @@ apiCall.then(function(respon The
idiomatic way to return a Response to an intercepted request in ServiceWorkers is:

-
-
addEventListener('fetch', function(event) {
+            
addEventListener('fetch', function(event) {
   event.respondWith(new Response("Response body", {
     headers: { "Content-Type" : "text/plain" }
   });
 });
-

As you can see, Response has a two argument constructor, where both arguments are optional. The first argument is a body initializer, and the second is a dictionary to set the status, statusText and headers.

@@ -363,20 +337,16 @@ apiCall.then(function(respon

This is a significant improvement over XHR in terms of ease of use of non-text data!

Request bodies can be set by passing body parameters:

-
-
var form = new FormData(document.getElementById('login-form'));
+            
var form = new FormData(document.getElementById('login-form'));
 fetch("/login", {
   method: "POST",
   body: form
 })
-

Responses take the first argument as the body.

-
-
var res = new Response(new File(["chunk", "chunk"], "archive.zip",
+                
var res = new Response(new File(["chunk", "chunk"], "archive.zip",
                        { type: "application/zip" }));
-

Both Request and Response (and by extension the fetch() function), will try to intelligently determine the content type. Request will also automatically set a “Content-Type” header if none is @@ -387,8 +357,7 @@ fetch("/login", {

It is important to realise that Request and Response bodies can only be read once! Both interfaces have a boolean attribute bodyUsed to determine if it is safe to read or not.

-
-
var res = new Response("one time use");
+                
var res = new Response("one time use");
 console.log(res.bodyUsed); // false
 res.text().then(function(v) {
   console.log(res.bodyUsed); // true
@@ -399,7 +368,6 @@ res.text().catch(log("Tried to read already consumed Response");
 });
-

This decision allows easing the transition to an eventual stream-based Fetch API. The intention is to let applications consume data as it arrives, allowing for JavaScript to deal with larger files like videos, and perform things @@ -413,8 +381,7 @@ res.text().catch(clone() MUST be called before the body of the corresponding object has been used. That is, clone() first, read later.

-
-
addEventListener('fetch', function(evt) {
+                
addEventListener('fetch', function(evt) {
   var sheep = new Response("Dolly");
   console.log(sheep.bodyUsed); // false
   var clone = sheep.clone();
@@ -429,7 +396,6 @@ res.text().catch(});
 });
-

Future improvements

-- cgit v1.2.3