From 62e49c5c1514cb6150150e282ecbf37cd0252e85 Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Wed, 24 Mar 2021 15:34:08 +0100 Subject: [PATCH] integrate pingback sending into PUT /webmention --- README.md | 43 ++++++++++++++++-- src/linkdiscoverer.js | 31 +++++++++---- src/pingback/send.js | 29 ++++++++++-- src/webmention/send.js | 34 ++++++++------ test/__mocks__/index.xml | 2 + test/__mocks__/link-discover-bothtypes.html | 12 +++++ .../pingback-discover-test-headers.json | 3 ++ .../pingback-discover-test-multiple.html | 12 +++++ .../pingback-discover-test-single.html | 11 +++++ test/__mocks__/pingback-discover-test.html | 12 +++++ test/linkdiscoverer.test.js | 44 ++++++++++++++++--- test/webmention/send.test.js | 23 +++++++++- 12 files changed, 219 insertions(+), 37 deletions(-) create mode 100644 test/__mocks__/link-discover-bothtypes.html create mode 100644 test/__mocks__/pingback-discover-test-headers.json create mode 100644 test/__mocks__/pingback-discover-test-multiple.html create mode 100644 test/__mocks__/pingback-discover-test-single.html create mode 100644 test/__mocks__/pingback-discover-test.html diff --git a/README.md b/README.md index c8ec18f..8c76335 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ If you want to support the older pingback protocol, you can leverage webmenton.i #### 1.1 `POST /webmention` -Post a webmention. Includes a _lot_ of cross-checking and validating to guard against possible spam. See the [W3C WebMention spec](https://www.w3.org/TR/webmention/#sender-notifies-receiver) - or the source - for details. +Receive a webmention. Includes a _lot_ of cross-checking and validating to guard against possible spam. See the [W3C WebMention spec](https://www.w3.org/TR/webmention/#sender-notifies-receiver) - or the source - for details. Accepted form format: @@ -42,14 +42,14 @@ Retrieves a JSON array with relevant webmentions stored for that domain. The tok #### 1.3 `PUT /webmention/:domain/:token` -Sends out webmentions, based on the domain's `index.xml` RSS feed, and optionally, a `since` request query parameter that is supposed to be a string, fed through [Dayjs](https://day.js.org/) to format. (e.g. `2021-03-16T16:00:00.000Z`). +Sends out **both webmentions and pingbacks**, based on the domain's `index.xml` RSS feed, and optionally, a `since` request query parameter that is supposed to be a string, fed through [Dayjs](https://day.js.org/) to format. (e.g. `2021-03-16T16:00:00.000Z`). This does a couple of things: 1. Fetch RSS entries (since x, or everything) 2. Find outbound `href`s (starting with `http`) -3. Check if those domains have a `webmention` link endpoint installed, according to the w3.org rules. -4. If so: `POST` for each found href with `source` the own domain and `target` the outbound link found in the RSS feed. +3. Check if those domains have a `webmention` link endpoint installed, according to the w3.org rules. If not, check for a `pingback` endpoint. If not, bail out. +4. If webmention/pingback found: `POST` for each found href with `source` the own domain and `target` the outbound link found in the RSS feed, using either XML or form data according to the protocol. As with the `POST` call, will result in a `202 Accepted` and handles things async/in parallel. @@ -57,6 +57,41 @@ As with the `POST` call, will result in a `202 Accepted` and handles things asyn Yes and no. It checks the `` `` RSS tag by default, but if a `