Functions for generating HTTP-related data.
Provides utilities to generate random HTTP values including user-agent strings, request methods, status codes, referrer policies, protocol versions, and header names.
Summary
Functions
Returns the list of all valid referrer policy strings.
Returns the list of all valid HTTP request methods.
Generates a random HTTP header name.
Generates a random HTTP protocol version string.
Generates a random HTTP referrer policy.
Generates a random HTTP request method.
Generates a random HTTP status code.
Generates a random HTTP user-agent.
Functions
@spec all_referrer_policies() :: [String.t()]
Returns the list of all valid referrer policy strings.
Examples
iex> NeoFaker.HTTP.all_referrer_policies()
["no-referrer", "no-referrer-when-downgrade", ...]
@spec all_request_methods() :: [String.t()]
Returns the list of all valid HTTP request methods.
Examples
iex> NeoFaker.HTTP.all_request_methods()
["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE", "CONNECT", "QUERY"]
Generates a random HTTP header name.
Returns a common request or response header name from a curated list of ten per category.
Options
:type(:all,:request, or:response) - the header category.:requestreturns headers such as"User-Agent";:responsereturns headers such as"Server". Defaults to:all(both categories combined).
Examples
iex> NeoFaker.HTTP.header_name()
"Content-Type"
iex> NeoFaker.HTTP.header_name(type: :request)
"User-Agent"
iex> NeoFaker.HTTP.header_name(type: :response)
"Server"
Generates a random HTTP protocol version string.
Randomly selects from HTTP/1.0, HTTP/1.1, HTTP/2, and optionally HTTP/3.
Options
:include_http3(boolean) - whenfalse, excludesHTTP/3from the pool. Defaults totrue.
Examples
iex> NeoFaker.HTTP.protocol_version()
"HTTP/1.1"
iex> NeoFaker.HTTP.protocol_version(include_http3: false)
"HTTP/1.0"
@spec referrer_policy() :: String.t()
Generates a random HTTP referrer policy.
Returns one of the eight standard Referrer-Policy header values.
Examples
iex> NeoFaker.HTTP.referrer_policy()
"no-referrer"
iex> NeoFaker.HTTP.referrer_policy()
"strict-origin-when-cross-origin"
Generates a random HTTP request method.
Returns one of the common methods (GET, POST, PUT, DELETE, PATCH, QUERY) by default.
Options
:common_only(boolean) - whenfalse, includes all ten standard methods instead of just the six most common. Defaults totrue.
Examples
iex> NeoFaker.HTTP.request_method()
"GET"
iex> NeoFaker.HTTP.request_method(common_only: false)
"OPTIONS"
Generates a random HTTP status code.
Returns either a simple code string (e.g. "200") or a detailed one (e.g. "200 OK").
Options
:type(:simpleor:detailed) -:simplereturns the code only;:detailedincludes the reason phrase. Defaults to:simple.:group(an atom below, ornil) - restricts sampling to one status code group. Defaults tonil(all groups).:information- 1xx Informational.:success- 2xx Success.:redirection- 3xx Redirection.:client_error- 4xx Client Error.:server_error- 5xx Server Error.
Examples
iex> NeoFaker.HTTP.status_code()
"200"
iex> NeoFaker.HTTP.status_code(type: :detailed)
"200 OK"
iex> NeoFaker.HTTP.status_code(group: :client_error)
"404"
iex> NeoFaker.HTTP.status_code(type: :detailed, group: :success)
"201 Created"
Generates a random HTTP user-agent.
Browsers are full user-agent strings; crawlers and AI agents are the bare bot tokens
("gptbot", "ahrefsbot") that identify them in a User-Agent header.
Options
:type(:all,:browser,:crawler, or:ai) - the user-agent category.:alldraws from every category. Defaults to:all.:browser- a real browser user-agent string.:crawler- a search/SEO crawler bot token.:ai- an AI crawler or agent bot token ("gptbot","claude-user","perplexitybot").
Examples
iex> NeoFaker.HTTP.user_agent()
"Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0"
iex> NeoFaker.HTTP.user_agent(type: :browser)
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0"
iex> NeoFaker.HTTP.user_agent(type: :crawler)
"ahrefsbot"
iex> NeoFaker.HTTP.user_agent(type: :ai)
"claude-user"