Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,45 @@ | ||
defmodule Crawler.Fetcher.Modifier do | ||
|
||
@moduledoc """ | ||
modify request options and headers before dispatch | ||
""" | ||
@moduledoc """ | ||
Modifies request options and headers before dispatch. | ||
""" | ||
|
||
defmodule Spec do | ||
@moduledoc """ | ||
Spec for defining a request modifier. | ||
""" | ||
defmodule Spec do | ||
@type url :: String.t | ||
@type header :: {String.t, String.t} | ||
@type opts :: map | ||
|
||
@type url :: String.t | ||
@type header :: {String.t, String.t} | ||
@type opts :: map | ||
@callback headers(opts) :: list(header) | [] | ||
@callback opts(opts) :: keyword | [] | ||
end | ||
|
||
@callback headers(opts) :: list(header) | [] | ||
@callback opts(opts) :: keyword | [] | ||
@behaviour __MODULE__.Spec | ||
|
||
@doc """ | ||
Allows modifing headers prior to making a crawl request. | ||
## Example implementaion | ||
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 | ||
@behaviour __MODULE__.Spec | ||
|
||
@doc """ | ||
Allows modifing headers prior to making the crawl request | ||
## Example implementaion | ||
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 | ||
## 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 |
This file contains 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
This file contains 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