Liking cljdoc? Tell your friends :D

dk.simongray.wary-fetch.proxy

A proxy on your own server for the requests of a web page, since most servers don't let a page of another origin read their answers.

The proxy fetches any public URL for whoever can reach it, so put it behind your login. Its answers come from other sites but have your site's origin, so it refuses to be opened as a page. When a browser opens an answer anyway, it runs no scripts in it.

A proxy on your own server for the requests of a web page, since most
servers don't let a page of another origin read their answers.

The proxy fetches any public URL for whoever can reach it, so put it
behind your login. Its answers come from other sites but have your
site's origin, so it refuses to be opened as a page. When a browser
opens an answer anyway, it runs no scripts in it.
raw docstring

defaultsclj/s

The default options of the proxy, which the options you give replace one by one:

  • :allow-pred, a predicate of the URLs that it fetches, url/public?
  • :send, the function that sends a request, http/send!
  • :forward, the request headers that go on to the other site
  • :expose, the response headers that come back to the page
  • :user-agent, the User-Agent of each request
  • :max-bytes, the most that a body can hold, 32 MB, since the proxy holds each body in memory

A :timeout-seconds in the options goes on each request too. The proxy never passes on the page's own cookies and credentials unless :forward names them.

The default options of the proxy, which the options you give replace
one by one:

- :allow-pred, a predicate of the URLs that it fetches, url/public?
- :send, the function that sends a request, http/send!
- :forward, the request headers that go on to the other site
- :expose, the response headers that come back to the page
- :user-agent, the User-Agent of each request
- :max-bytes, the most that a body can hold, 32 MB, since the proxy
  holds each body in memory

A :timeout-seconds in the options goes on each request too. The proxy
never passes on the page's own cookies and credentials unless :forward
names them.
sourceraw docstring

error-responseclj/s

(error-response e)

The Ring response for the exception e that the proxy's :send threw, with an RFC 9209 Proxy-Status from which the page makes the same exception again.

The Ring response for the exception `e` that the proxy's :send threw,
with an RFC 9209 Proxy-Status from which the page makes the same
exception again.
sourceraw docstring

handlerclj

(handler)
(handler opts)

A Ring handler that sends each GET and HEAD request on to the URL in its url parameter, with opts over defaults, and answers with what came back.

Mount it at a route behind your login, with any Ring router (e.g. Reitit or Compojure) on any Ring server (e.g. ring-jetty or http-kit).

A Ring handler that sends each GET and HEAD request on to the URL in
its url parameter, with `opts` over defaults, and answers with what
came back.

Mount it at a route behind your login, with any Ring router (e.g.
Reitit or Compojure) on any Ring server (e.g. ring-jetty or
http-kit).
sourceraw docstring

proxiedclj/s

(proxied base {:keys [url as] :as request})

The request to send through the proxy at base: to base with the request's URL as the url parameter, and without its :allow-pred, which the proxy applies itself.

The `request` to send through the proxy at `base`: to `base` with the
request's URL as the url parameter, and without its :allow-pred, which
the proxy applies itself.
sourceraw docstring

refusalclj/s

(refusal {:keys [request-method] :as ring-request})

The Ring response that refuses ring-request, or nil when the proxy sends it on. The proxy refuses:

  • a method other than GET and HEAD
  • a request that it sent itself, by its Via header
  • a page that opens it as a document, or a page of another site, by the browser's Sec-Fetch-Mode and Sec-Fetch-Site headers
  • a request without an http or https URL as its url parameter
The Ring response that refuses `ring-request`, or nil when the proxy
sends it on. The proxy refuses:

- a method other than GET and HEAD
- a request that it sent itself, by its Via header
- a page that opens it as a document, or a page of another site, by the
  browser's Sec-Fetch-Mode and Sec-Fetch-Site headers
- a request without an http or https URL as its url parameter
sourceraw docstring

ring-responseclj/s

(ring-response response)
(ring-response {:keys [status url permanent-url headers body] :as response}
               {:keys [expose] :or {expose (:expose defaults)} :as opts})

The Ring response that passes the response of a page's request back to the page, with the headers that the :expose of opts (or of defaults) names.

A text body goes as UTF-8, which is how fetch in a page decodes it, and a text type gets that charset. Any other type stays as it came, so ask for bytes for a body that isn't text. The URL that answered after redirects is the Content-Location (RFC 9110, section 8.7). The URL that permanent redirects led to is the Wary-Fetch-Permanent-Location.

A redirect that the client didn't follow, e.g. from https to http, keeps its status, and its Location goes as the Wary-Fetch-Location.

The Ring response that passes the `response` of a page's request back to
the page, with the headers that the :expose of `opts` (or of defaults)
names.

A text body goes as UTF-8, which is how fetch in a page decodes it, and
a text type gets that charset. Any other type stays as it came, so ask
for bytes for a body that isn't text. The URL that answered after
redirects is the Content-Location (RFC 9110, section 8.7). The URL that
permanent redirects led to is the Wary-Fetch-Permanent-Location.

A redirect that the client didn't follow, e.g. from https to http, keeps
its status, and its Location goes as the Wary-Fetch-Location.
sourceraw docstring

senderclj/s

(sender base)
(sender base {:keys [send] :or {send http/send!} :as opts})

A function to pass as :send, which sends each request through the proxy at base with the opts and returns what a direct request would.

The base is the URL of the proxy's route, e.g. /proxy in a page. Each request goes with the :send of opts, http/send! by default. A request whose URL isn't http or https (e.g. a WebSocket that a page opens by itself) goes to that :send as it is.

A function to pass as :send, which sends each request through the proxy
at `base` with the `opts` and returns what a direct request would.

The `base` is the URL of the proxy's route, e.g. /proxy in a page. Each
request goes with the :send of `opts`, http/send! by default. A request
whose URL isn't http or https (e.g. a WebSocket that a page opens by
itself) goes to that :send as it is.
sourceraw docstring

stream-defaultsclj/s

The default options of the streaming proxy, which the options you give replace one by one. They're those of defaults except for these, since it holds no body in memory:

  • :max-bytes, the most that one answer passes on, 2 GB
  • :stream-seconds, the longest that one answer may take to pass on, an hour
  • :expose, also the Accept-Ranges and the Content-Length

They have no :send, since the JDK's client sends each request.

The default options of the streaming proxy, which the options you give
replace one by one. They're those of defaults except for these, since it
holds no body in memory:

- :max-bytes, the most that one answer passes on, 2 GB
- :stream-seconds, the longest that one answer may take to pass on, an
  hour
- :expose, also the Accept-Ranges and the Content-Length

They have no :send, since the JDK's client sends each request.
sourceraw docstring

stream-handlerclj

(stream-handler)
(stream-handler opts)

A Ring handler that sends each GET and HEAD request on to the URL in its url parameter, as handler does, with opts over stream-defaults, but passes on the body as it arrives rather than holding it, e.g. for an episode that a page saves.

The body goes on as it came, without gzip undone or text decoded. A Range goes on too, so that a page can resume a download. The proxy follows redirects itself and checks each URL with :allow-pred.

A Ring handler that sends each GET and HEAD request on to the URL in
its url parameter, as handler does, with `opts` over stream-defaults,
but passes on the body as it arrives rather than holding it, e.g. for
an episode that a page saves.

The body goes on as it came, without gzip undone or text decoded. A
Range goes on too, so that a page can resume a download. The proxy
follows redirects itself and checks each URL with :allow-pred.
sourceraw docstring

unproxiedclj/s

(unproxied request {:keys [headers] :as response})

The proxy's response to request, as a direct request would return it.

The response has the :url that answered after redirects, the :permanent-url that permanent redirects led to and the Location of a redirect that wasn't followed. When the proxy failed to send the request, this throws the exception that a direct request would have thrown, with the same :type.

The proxy's `response` to `request`, as a direct request would return
it.

The response has the :url that answered after redirects, the
:permanent-url that permanent redirects led to and the Location of a
redirect that wasn't followed. When the proxy failed to send the
request, this throws the exception that a direct request would have
thrown, with the same :type.
sourceraw docstring

upstream-requestclj/s

(upstream-request ring-request)
(upstream-request {:keys [request-method] :as ring-request} opts)

The request that the proxy sends for ring-request, with opts over defaults, or nil when the url parameter names no http or https URL.

The request has the headers that the :forward of opts names, the proxy's Via, and the range of a Range header with a single range, so that the proxy reads no more than the page asked for. Its body is bytes when the as parameter is bytes, and text otherwise.

The request that the proxy sends for `ring-request`, with `opts` over
defaults, or nil when the url parameter names no http or https URL.

The request has the headers that the :forward of `opts` names, the
proxy's Via, and the range of a Range header with a single range, so
that the proxy reads no more than the page asked for. Its body is bytes
when the as parameter is bytes, and text otherwise.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close