-
Notifications
You must be signed in to change notification settings - Fork 91
/
modifier.ex
45 lines (36 loc) · 973 Bytes
/
modifier.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
defmodule Crawler.Fetcher.Modifier do
@moduledoc """
Modifies request options and headers before dispatch.
"""
defmodule Spec do
@type url :: String.t()
@type header :: {String.t(), String.t()}
@type opts :: map
@callback headers(opts) :: list(header) | []
@callback opts(opts) :: keyword | []
end
@behaviour __MODULE__.Spec
@doc """
Allows modifying headers prior to making a crawl request.
## Example implementation
def headers(opts) do
if opts[:url] == "http://modifier" do
[{"Referer", "http://fetcher"}]
end
[]
end
"""
def headers(_opts), do: []
@doc """
Allows passing opts to httpPoison prior to making the crawl request
## Example implementation
def opts(opts) do
if opts[:url] == "http://modifier" do
# add a new pool to hackney
[hackney: [pool: :modifier]]
end
[]
end
"""
def opts(_opts), do: []
end