random-header-generator


Namerandom-header-generator JSON
Version 1.2 PyPI version JSON
download
home_page
SummaryGenerator of random, realistic http headers.
upload_time2023-03-26 05:35:23
maintainer
docs_urlNone
authormiltos_90
requires_python>=3.10
licenseGNU General Public License v3.0
keywords python headers http
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Random HTTP Header Generator

## Description
The **random-header-generator** package can be used to generate random, yet realistic, http request headers. 

It is inspired by the excellent [ua-parser](https://github.com/faisalman/ua-parser-js), [apify](https://github.com/apify/header-generator), and [fake-http-header](https://github.com/MichaelTatarski/fake-http-header/tree/main/fake_http_header) repositories, and it emulates real browser behaviour for the following header fields:

* User-Agent
* Referer
* Accept
* Accept-Language
* Accept-Encoding
* Sec-Fetch-Site
* Sec-Fetch-Mode
* Sec-Fetch-User
* Sec-Fetch-Dest
* Upgrade-Insecure-Requests
* Connection

In addition, it supports the following [Client Hints](https://wicg.github.io/client-hints-infrastructure/):
* Sec-CH-UA
* Sec-CH-UA-Arch
* Sec-CH-UA-Bitness
* Sec-CH-UA-Full-Version-List
* Sec-CH-UA-Mobile
* Sec-CH-UA-Model
* Sec-CH-UA-Platform
* Sec-CH-UA-Platform-Version

The generated headers conform to http-version specific ordering and support [rules](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers), and are browser-, version-, and country- specific. 

In particular, the available headers cover the following:
* Browsers: Chrome, Edge, Firefox, Safari, Opera
* Device types: Desktop, Mobile
* HTTP Versions: 1.x, 2.0
* Countries: According to the [alpha-2 ISO codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the following table:

<table>
  <tr>
    <td colspan="15", rowspan="1", align = "center">Supported alpha-2 ISO codes.</td>
  </tr>
  <tr>
    <td>ad</td>
    <td>ae</td>
    <td>af</td>
    <td>ag</td>
    <td>al</td>
    <td>am</td>
    <td>ao</td>
    <td>ar</td>
    <td>as</td>
    <td>at</td>
    <td>au</td>
    <td>az</td>
    <td>ba</td>
    <td>bb</td>
    <td>bd</td>
  </tr>
  <tr>
    <td>be</td>
    <td>bf</td>
    <td>bg</td>
    <td>bh</td>
    <td>bi</td>
    <td>bj</td>
    <td>bo</td>
    <td>br</td>
    <td>bs</td>
    <td>bt</td>
    <td>bw</td>
    <td>by</td>
    <td>bz</td>
    <td>ca</td>
    <td>cd</td>
  </tr>
  <tr>
    <td>ch</td>
    <td>cl</td>
    <td>cm</td>
    <td>cn</td>
    <td>co</td>
    <td>cr</td>
    <td>cu</td>
    <td>cy</td>
    <td>cz</td>
    <td>de</td>
    <td>dj</td>
    <td>dk</td>
    <td>dm</td>
    <td>do</td>
    <td>dz</td>
  </tr>
  <tr>
    <td>ec</td>
    <td>ee</td>
    <td>eg</td>
    <td>er</td>
    <td>es</td>
    <td>et</td>
    <td>fi</td>
    <td>fj</td>
    <td>fr</td>
    <td>ga</td>
    <td>gb</td>
    <td>gd</td>
    <td>ge</td>
    <td>gh</td>
    <td>gm</td>
  </tr>
  <tr>
    <td>gn</td>
    <td>gq</td>
    <td>gr</td>
    <td>gt</td>
    <td>gw</td>
    <td>gy</td>
    <td>hn</td>
    <td>hr</td>
    <td>ht</td>
    <td>hu</td>
    <td>id</td>
    <td>ie</td>
    <td>il</td>
    <td>in</td>
    <td>iq</td>
  </tr>
  <tr>
    <td>ir</td>
    <td>is</td>
    <td>it</td>
    <td>jm</td>
    <td>jo</td>
    <td>jp</td>
    <td>ke</td>
    <td>kg</td>
    <td>kh</td>
    <td>ki</td>
    <td>km</td>
    <td>kn</td>
    <td>kw</td>
    <td>kz</td>
    <td>lb</td>
  </tr>
  <tr>
    <td>lc</td>
    <td>li</td>
    <td>lk</td>
    <td>lr</td>
    <td>ls</td>
    <td>lt</td>
    <td>lu</td>
    <td>lv</td>
    <td>ly</td>
    <td>ma</td>
    <td>mc</td>
    <td>md</td>
    <td>me</td>
    <td>mg</td>
    <td>mh</td>
  </tr>
  <tr>
    <td>ml</td>
    <td>mn</td>
    <td>mr</td>
    <td>mt</td>
    <td>mu</td>
    <td>mw</td>
    <td>mx</td>
    <td>my</td>
    <td>mz</td>
    <td>ne</td>
    <td>ng</td>
    <td>ni</td>
    <td>nl</td>
    <td>no</td>
    <td>np</td>
  </tr>
  <tr>
    <td>nr</td>
    <td>nu</td>
    <td>nz</td>
    <td>om</td>
    <td>pa</td>
    <td>pe</td>
    <td>pg</td>
    <td>ph</td>
    <td>pk</td>
    <td>pl</td>
    <td>ps</td>
    <td>pt</td>
    <td>py</td>
    <td>qa</td>
    <td>ro</td>
  </tr>
  <tr>
    <td>rs</td>
    <td>ru</td>
    <td>rw</td>
    <td>sa</td>
    <td>sb</td>
    <td>sc</td>
    <td>sd</td>
    <td>se</td>
    <td>sg</td>
    <td>si</td>
    <td>sk</td>
    <td>sl</td>
    <td>sm</td>
    <td>sn</td>
    <td>so</td>
  </tr>
  <tr>
    <td>sr</td>
    <td>ss</td>
    <td>sv</td>
    <td>sz</td>
    <td>td</td>
    <td>tg</td>
    <td>th</td>
    <td>tj</td>
    <td>tm</td>
    <td>tn</td>
    <td>to</td>
    <td>tr</td>
    <td>tt</td>
    <td>tv</td>
    <td>tw</td>
  </tr>
  <tr>
    <td>tz</td>
    <td>ua</td>
    <td>ug</td>
    <td>us</td>
    <td>uy</td>
    <td>uz</td>
    <td>vc</td>
    <td>ve</td>
    <td>vn</td>
    <td>vu</td>
    <td>ye</td>
    <td>za</td>
    <td>zm</td>
    <td>zw</td>
    <td></td>
  </tr>
</table>
      
If any of the above inputs are not supplied by the user, they will be populated in line with browser and device market share data, as well as internet usage per country data (see data_notes.md for a complete list of data sources). In addition, for the headers that support relative quality factors, the latter have 50% chance of being included in the headers' values.

User agents can be generated in one of the following ways:
* **programmatically generated** utilising most of the templates of the [ua-generator](https://github.com/iamdual/ua-generator) repo, with additional modifications and extensions,
* **scraped** from the [*user agent string*](https://www.useragentstring.com/) website,
* **parsed** from a user-provided .txt file.

## Installation

The package can be easily installed via pip:

```bash
pip install random-header-generator
```

## Usage

The generation of headers is very straight-forward, and can be performed in a variety of ways. The generator can be instantiated with one of the following:

```python
from random_header_generator import HeaderGenerator

# Approach 1
generator = HeaderGenerator() # defaults to user_agents = 'program'

# Approach 2
generator = HeaderGenerator(user_agents = 'program')

# Approach 3
generator = HeaderGenerator(user_agents = 'scrape')

# Approach 4
generator = HeaderGenerator(user_agents = 'file', filename = 'path/to/agents/file.txt')

```

* Methods 1-2 are equivalent and indicate that the user agents will be generated programmatically using built-in templates.
* Method 3 indicates that the latest user agents will be scraped from https://www.useragentstring.com/
* Method 4 indicates that the user agents will be read from the .txt file whose path is provided in the *filename* argument.

Regarding Method 4, the user agent .txt file is assumed to contain a list of user agents, each one followed by a newline character as follows:
```
Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
...
```

Having instantiated a generator with one of the approaches outline above, the headers can be generated with a variety of ways, specifying any combination of the following input arguments:

In particular, the available headers cover the following:
* `browser`: A string with one of the following values: 'chrome', 'edge', 'firefox', 'safari', 'opera'
* `device` : A string indicating the device type, with applicable value being 'desktop' or 'mobile'
* `http_version`: An integer indicating if the headers correspond to HTTP version 1.x (1), or 2.0 (2)
* `country`: A string containing a supported [alpha-2 ISO code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2), defined in the table above.
* `cookies`: A dictionary with keys and values being the cookie names and corresponding values. If not specified or when empty `cookies = {}`, a 'Cookie' header will not be included in the output.

### Example 1
 The simplest approach is to just call the constructor method for the header *HeaderGenerator* class without any parameters:

```python
# generator has been instantiated using one of the 4 approaches defined above...

headers = generator() # returns an ordered dict
    
for k, v in headers.items():
  print(f'{k}: {v}')
```

`headers` is an ordered dict, whose keys are the HTTP header fields along with their corresponding values. The code snipped prints the following (your output will most likely differ due to randomization):

```bash
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 7.1; Nexus 9; Build/N9F27G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.203 Mobile Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Sec-Fetch-Mode: navigate
Sec-Fetch-Dest: document
Sec-Fetch-Site: same-site
Sec-Fetch-User: ?1
Referer: http://www.acoon.de
Accept-Encoding: br, identity, *
Accept-Language: en-US,en-GB;q=0.8,de-DE;q=0.5,en;q=0.2
```

When no arguments are provided the country, device, and browser are generated via a weighted random selection according to usage/market data (see /data/notes.md), and the headers are valid for HTTP version 1.1.

### Example 2

An example with all possible user inputs being specified is the following:

```python
# generator has been instantiated using one of the 4 approaches defined above...

headers   = generator(
  country     = 'us', 
  device      = 'desktop', 
  browser     = 'chrome',
  httpVersion = 1,
  cookies     = {'cookie_ID_1': 'cookie_Value_1', 'cookie_ID_2': 'cookie_value_2'},
)
    
for k, v in headers.items():
  print(f'{k}: {v}')
```
with the corresponding output being:

```bash
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.38 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Sec-Fetch-Mode: navigate
Sec-Fetch-Dest: document
Sec-Fetch-Site: same-site
Sec-Fetch-User: ?1
Referer: http://vector.us
Accept-Encoding: gzip, identity, deflate, compress, *
Accept-Language: es-US,en-US;q=0.8,en-GB;q=0.5,en;q=0.2
Cookie: cookie_ID_2=cookie_value_2; cookie_ID_1=cookie_Value_1
Sec-CH-UA: "Chromium";v="94", "Google Chrome";v="94", " Not A;Brand";v="99"
Sec-CH-UA-Arch: ""
Sec-CH-UA-Bitness: ""
Sec-CH-UA-Mobile: ?0
Sec-CH-UA-Model: "Macintosh"
Sec-CH-UA-Platform: "Mac OS"
Sec-CH-UA-Platform-Version: "11.6.1"
```

### Example 3

An example with partial input specification is the following:

```python
# generator has been instantiated using one of the 4 approaches defined above...

headers = generator(country = 'de', httpVersion = 2)
    
for k, v in headers.items():
  print(f'{k}: {v}')
```

with possible outputs being:

```bash
sec-ch-ua: "Chromium";v="104", "Google Chrome";v="104", " Not A;Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Android"
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Linux; Android 6; Nexus 9; Build/MMB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.132 Mobile Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
sec-fetch-site: same-site
sec-fetch-mode: navigate
sec-fetch-user: ?1
sec-fetch-dest: document
referer: http://www.financiero.de
accept-encoding: gzip, compress
accept-language: en,de-DE;q=0.7,en-US;q=0.5,en-GB;q=0.3
sec-ch-ua-arch: ""
sec-ch-ua-bitness: ""
sec-ch-ua-full-version-list: "Chromium";v="104.0.5112.132", "Google Chrome";v="104.0.5112.132", " Not A;Brand";v="99.0.0.0"
sec-ch-ua-model: "Nexus 9"
sec-ch-ua-platform-version: "6"
connection: keep-alive
```

or

```bash
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) CriOS/77.0.3865.181 Mobile/15E148 Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
sec-fetch-site: same-site
sec-fetch-mode: navigate
sec-fetch-user: ?1
referer: https://www.google.com
accept-encoding: compress
accept-language: en-US,de-DE,en-GB,en
connection: keep-alive
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "random-header-generator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "python,headers,http",
    "author": "miltos_90",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/f6/ca/09c955e164f7eb9181a7b2a199335ebbd3e441067cd2c6f51f769bb9a750/random-header-generator-1.2.tar.gz",
    "platform": null,
    "description": "# Random HTTP Header Generator\n\n## Description\nThe **random-header-generator** package can be used to generate random, yet realistic, http request headers. \n\nIt is inspired by the excellent [ua-parser](https://github.com/faisalman/ua-parser-js), [apify](https://github.com/apify/header-generator), and [fake-http-header](https://github.com/MichaelTatarski/fake-http-header/tree/main/fake_http_header) repositories, and it emulates real browser behaviour for the following header fields:\n\n* User-Agent\n* Referer\n* Accept\n* Accept-Language\n* Accept-Encoding\n* Sec-Fetch-Site\n* Sec-Fetch-Mode\n* Sec-Fetch-User\n* Sec-Fetch-Dest\n* Upgrade-Insecure-Requests\n* Connection\n\nIn addition, it supports the following [Client Hints](https://wicg.github.io/client-hints-infrastructure/):\n* Sec-CH-UA\n* Sec-CH-UA-Arch\n* Sec-CH-UA-Bitness\n* Sec-CH-UA-Full-Version-List\n* Sec-CH-UA-Mobile\n* Sec-CH-UA-Model\n* Sec-CH-UA-Platform\n* Sec-CH-UA-Platform-Version\n\nThe generated headers conform to http-version specific ordering and support [rules](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers), and are browser-, version-, and country- specific. \n\nIn particular, the available headers cover the following:\n* Browsers: Chrome, Edge, Firefox, Safari, Opera\n* Device types: Desktop, Mobile\n* HTTP Versions: 1.x, 2.0\n* Countries: According to the [alpha-2 ISO codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the following table:\n\n<table>\n  <tr>\n    <td colspan=\"15\", rowspan=\"1\", align = \"center\">Supported alpha-2 ISO codes.</td>\n  </tr>\n  <tr>\n    <td>ad</td>\n    <td>ae</td>\n    <td>af</td>\n    <td>ag</td>\n    <td>al</td>\n    <td>am</td>\n    <td>ao</td>\n    <td>ar</td>\n    <td>as</td>\n    <td>at</td>\n    <td>au</td>\n    <td>az</td>\n    <td>ba</td>\n    <td>bb</td>\n    <td>bd</td>\n  </tr>\n  <tr>\n    <td>be</td>\n    <td>bf</td>\n    <td>bg</td>\n    <td>bh</td>\n    <td>bi</td>\n    <td>bj</td>\n    <td>bo</td>\n    <td>br</td>\n    <td>bs</td>\n    <td>bt</td>\n    <td>bw</td>\n    <td>by</td>\n    <td>bz</td>\n    <td>ca</td>\n    <td>cd</td>\n  </tr>\n  <tr>\n    <td>ch</td>\n    <td>cl</td>\n    <td>cm</td>\n    <td>cn</td>\n    <td>co</td>\n    <td>cr</td>\n    <td>cu</td>\n    <td>cy</td>\n    <td>cz</td>\n    <td>de</td>\n    <td>dj</td>\n    <td>dk</td>\n    <td>dm</td>\n    <td>do</td>\n    <td>dz</td>\n  </tr>\n  <tr>\n    <td>ec</td>\n    <td>ee</td>\n    <td>eg</td>\n    <td>er</td>\n    <td>es</td>\n    <td>et</td>\n    <td>fi</td>\n    <td>fj</td>\n    <td>fr</td>\n    <td>ga</td>\n    <td>gb</td>\n    <td>gd</td>\n    <td>ge</td>\n    <td>gh</td>\n    <td>gm</td>\n  </tr>\n  <tr>\n    <td>gn</td>\n    <td>gq</td>\n    <td>gr</td>\n    <td>gt</td>\n    <td>gw</td>\n    <td>gy</td>\n    <td>hn</td>\n    <td>hr</td>\n    <td>ht</td>\n    <td>hu</td>\n    <td>id</td>\n    <td>ie</td>\n    <td>il</td>\n    <td>in</td>\n    <td>iq</td>\n  </tr>\n  <tr>\n    <td>ir</td>\n    <td>is</td>\n    <td>it</td>\n    <td>jm</td>\n    <td>jo</td>\n    <td>jp</td>\n    <td>ke</td>\n    <td>kg</td>\n    <td>kh</td>\n    <td>ki</td>\n    <td>km</td>\n    <td>kn</td>\n    <td>kw</td>\n    <td>kz</td>\n    <td>lb</td>\n  </tr>\n  <tr>\n    <td>lc</td>\n    <td>li</td>\n    <td>lk</td>\n    <td>lr</td>\n    <td>ls</td>\n    <td>lt</td>\n    <td>lu</td>\n    <td>lv</td>\n    <td>ly</td>\n    <td>ma</td>\n    <td>mc</td>\n    <td>md</td>\n    <td>me</td>\n    <td>mg</td>\n    <td>mh</td>\n  </tr>\n  <tr>\n    <td>ml</td>\n    <td>mn</td>\n    <td>mr</td>\n    <td>mt</td>\n    <td>mu</td>\n    <td>mw</td>\n    <td>mx</td>\n    <td>my</td>\n    <td>mz</td>\n    <td>ne</td>\n    <td>ng</td>\n    <td>ni</td>\n    <td>nl</td>\n    <td>no</td>\n    <td>np</td>\n  </tr>\n  <tr>\n    <td>nr</td>\n    <td>nu</td>\n    <td>nz</td>\n    <td>om</td>\n    <td>pa</td>\n    <td>pe</td>\n    <td>pg</td>\n    <td>ph</td>\n    <td>pk</td>\n    <td>pl</td>\n    <td>ps</td>\n    <td>pt</td>\n    <td>py</td>\n    <td>qa</td>\n    <td>ro</td>\n  </tr>\n  <tr>\n    <td>rs</td>\n    <td>ru</td>\n    <td>rw</td>\n    <td>sa</td>\n    <td>sb</td>\n    <td>sc</td>\n    <td>sd</td>\n    <td>se</td>\n    <td>sg</td>\n    <td>si</td>\n    <td>sk</td>\n    <td>sl</td>\n    <td>sm</td>\n    <td>sn</td>\n    <td>so</td>\n  </tr>\n  <tr>\n    <td>sr</td>\n    <td>ss</td>\n    <td>sv</td>\n    <td>sz</td>\n    <td>td</td>\n    <td>tg</td>\n    <td>th</td>\n    <td>tj</td>\n    <td>tm</td>\n    <td>tn</td>\n    <td>to</td>\n    <td>tr</td>\n    <td>tt</td>\n    <td>tv</td>\n    <td>tw</td>\n  </tr>\n  <tr>\n    <td>tz</td>\n    <td>ua</td>\n    <td>ug</td>\n    <td>us</td>\n    <td>uy</td>\n    <td>uz</td>\n    <td>vc</td>\n    <td>ve</td>\n    <td>vn</td>\n    <td>vu</td>\n    <td>ye</td>\n    <td>za</td>\n    <td>zm</td>\n    <td>zw</td>\n    <td></td>\n  </tr>\n</table>\n      \nIf any of the above inputs are not supplied by the user, they will be populated in line with browser and device market share data, as well as internet usage per country data (see data_notes.md for a complete list of data sources). In addition, for the headers that support relative quality factors, the latter have 50% chance of being included in the headers' values.\n\nUser agents can be generated in one of the following ways:\n* **programmatically generated** utilising most of the templates of the [ua-generator](https://github.com/iamdual/ua-generator) repo, with additional modifications and extensions,\n* **scraped** from the [*user agent string*](https://www.useragentstring.com/) website,\n* **parsed** from a user-provided .txt file.\n\n## Installation\n\nThe package can be easily installed via pip:\n\n```bash\npip install random-header-generator\n```\n\n## Usage\n\nThe generation of headers is very straight-forward, and can be performed in a variety of ways. The generator can be instantiated with one of the following:\n\n```python\nfrom random_header_generator import HeaderGenerator\n\n# Approach 1\ngenerator = HeaderGenerator() # defaults to user_agents = 'program'\n\n# Approach 2\ngenerator = HeaderGenerator(user_agents = 'program')\n\n# Approach 3\ngenerator = HeaderGenerator(user_agents = 'scrape')\n\n# Approach 4\ngenerator = HeaderGenerator(user_agents = 'file', filename = 'path/to/agents/file.txt')\n\n```\n\n* Methods 1-2 are equivalent and indicate that the user agents will be generated programmatically using built-in templates.\n* Method 3 indicates that the latest user agents will be scraped from https://www.useragentstring.com/\n* Method 4 indicates that the user agents will be read from the .txt file whose path is provided in the *filename* argument.\n\nRegarding Method 4, the user agent .txt file is assumed to contain a list of user agents, each one followed by a newline character as follows:\n```\nMozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)\nMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36\nMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36\nMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36\nMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36\n...\n```\n\nHaving instantiated a generator with one of the approaches outline above, the headers can be generated with a variety of ways, specifying any combination of the following input arguments:\n\nIn particular, the available headers cover the following:\n* `browser`: A string with one of the following values: 'chrome', 'edge', 'firefox', 'safari', 'opera'\n* `device` : A string indicating the device type, with applicable value being 'desktop' or 'mobile'\n* `http_version`: An integer indicating if the headers correspond to HTTP version 1.x (1), or 2.0 (2)\n* `country`: A string containing a supported [alpha-2 ISO code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2), defined in the table above.\n* `cookies`: A dictionary with keys and values being the cookie names and corresponding values. If not specified or when empty `cookies = {}`, a 'Cookie' header will not be included in the output.\n\n### Example 1\n The simplest approach is to just call the constructor method for the header *HeaderGenerator* class without any parameters:\n\n```python\n# generator has been instantiated using one of the 4 approaches defined above...\n\nheaders = generator() # returns an ordered dict\n    \nfor k, v in headers.items():\n  print(f'{k}: {v}')\n```\n\n`headers` is an ordered dict, whose keys are the HTTP header fields along with their corresponding values. The code snipped prints the following (your output will most likely differ due to randomization):\n\n```bash\nConnection: keep-alive\nUpgrade-Insecure-Requests: 1\nUser-Agent: Mozilla/5.0 (Linux; Android 7.1; Nexus 9; Build/N9F27G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.203 Mobile Safari/537.36\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\nSec-Fetch-Mode: navigate\nSec-Fetch-Dest: document\nSec-Fetch-Site: same-site\nSec-Fetch-User: ?1\nReferer: http://www.acoon.de\nAccept-Encoding: br, identity, *\nAccept-Language: en-US,en-GB;q=0.8,de-DE;q=0.5,en;q=0.2\n```\n\nWhen no arguments are provided the country, device, and browser are generated via a weighted random selection according to usage/market data (see /data/notes.md), and the headers are valid for HTTP version 1.1.\n\n### Example 2\n\nAn example with all possible user inputs being specified is the following:\n\n```python\n# generator has been instantiated using one of the 4 approaches defined above...\n\nheaders   = generator(\n  country     = 'us', \n  device      = 'desktop', \n  browser     = 'chrome',\n  httpVersion = 1,\n  cookies     = {'cookie_ID_1': 'cookie_Value_1', 'cookie_ID_2': 'cookie_value_2'},\n)\n    \nfor k, v in headers.items():\n  print(f'{k}: {v}')\n```\nwith the corresponding output being:\n\n```bash\nConnection: keep-alive\nUpgrade-Insecure-Requests: 1\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.38 Safari/537.36\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\nSec-Fetch-Mode: navigate\nSec-Fetch-Dest: document\nSec-Fetch-Site: same-site\nSec-Fetch-User: ?1\nReferer: http://vector.us\nAccept-Encoding: gzip, identity, deflate, compress, *\nAccept-Language: es-US,en-US;q=0.8,en-GB;q=0.5,en;q=0.2\nCookie: cookie_ID_2=cookie_value_2; cookie_ID_1=cookie_Value_1\nSec-CH-UA: \"Chromium\";v=\"94\", \"Google Chrome\";v=\"94\", \" Not A;Brand\";v=\"99\"\nSec-CH-UA-Arch: \"\"\nSec-CH-UA-Bitness: \"\"\nSec-CH-UA-Mobile: ?0\nSec-CH-UA-Model: \"Macintosh\"\nSec-CH-UA-Platform: \"Mac OS\"\nSec-CH-UA-Platform-Version: \"11.6.1\"\n```\n\n### Example 3\n\nAn example with partial input specification is the following:\n\n```python\n# generator has been instantiated using one of the 4 approaches defined above...\n\nheaders = generator(country = 'de', httpVersion = 2)\n    \nfor k, v in headers.items():\n  print(f'{k}: {v}')\n```\n\nwith possible outputs being:\n\n```bash\nsec-ch-ua: \"Chromium\";v=\"104\", \"Google Chrome\";v=\"104\", \" Not A;Brand\";v=\"99\"\nsec-ch-ua-mobile: ?0\nsec-ch-ua-platform: \"Android\"\nupgrade-insecure-requests: 1\nuser-agent: Mozilla/5.0 (Linux; Android 6; Nexus 9; Build/MMB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.132 Mobile Safari/537.36\naccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\nsec-fetch-site: same-site\nsec-fetch-mode: navigate\nsec-fetch-user: ?1\nsec-fetch-dest: document\nreferer: http://www.financiero.de\naccept-encoding: gzip, compress\naccept-language: en,de-DE;q=0.7,en-US;q=0.5,en-GB;q=0.3\nsec-ch-ua-arch: \"\"\nsec-ch-ua-bitness: \"\"\nsec-ch-ua-full-version-list: \"Chromium\";v=\"104.0.5112.132\", \"Google Chrome\";v=\"104.0.5112.132\", \" Not A;Brand\";v=\"99.0.0.0\"\nsec-ch-ua-model: \"Nexus 9\"\nsec-ch-ua-platform-version: \"6\"\nconnection: keep-alive\n```\n\nor\n\n```bash\nupgrade-insecure-requests: 1\nuser-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) CriOS/77.0.3865.181 Mobile/15E148 Safari/537.36\naccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\nsec-fetch-site: same-site\nsec-fetch-mode: navigate\nsec-fetch-user: ?1\nreferer: https://www.google.com\naccept-encoding: compress\naccept-language: en-US,de-DE,en-GB,en\nconnection: keep-alive\n```\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3.0",
    "summary": "Generator of random, realistic http headers.",
    "version": "1.2",
    "split_keywords": [
        "python",
        "headers",
        "http"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75bac5dc1e9275fbb69d681290a004e9c5e0a7b107c068bc99d0a06a0c950fc2",
                "md5": "05432f8ea9ae48ecfe83f50b60c114de",
                "sha256": "8109eb9f7336770e55feb926a51c61eca3772a2834f11a358615c9a2803be169"
            },
            "downloads": -1,
            "filename": "random_header_generator-1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "05432f8ea9ae48ecfe83f50b60c114de",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 64814,
            "upload_time": "2023-03-26T05:35:21",
            "upload_time_iso_8601": "2023-03-26T05:35:21.554957Z",
            "url": "https://files.pythonhosted.org/packages/75/ba/c5dc1e9275fbb69d681290a004e9c5e0a7b107c068bc99d0a06a0c950fc2/random_header_generator-1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6ca09c955e164f7eb9181a7b2a199335ebbd3e441067cd2c6f51f769bb9a750",
                "md5": "56ccf0ff35dec0da34f348abd9f5177a",
                "sha256": "df21dfbe8d78f05eb6f3d757af020b753cee15036fbe957f0ec4afe5e22dfba8"
            },
            "downloads": -1,
            "filename": "random-header-generator-1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "56ccf0ff35dec0da34f348abd9f5177a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 62963,
            "upload_time": "2023-03-26T05:35:23",
            "upload_time_iso_8601": "2023-03-26T05:35:23.363575Z",
            "url": "https://files.pythonhosted.org/packages/f6/ca/09c955e164f7eb9181a7b2a199335ebbd3e441067cd2c6f51f769bb9a750/random-header-generator-1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-26 05:35:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "random-header-generator"
}
        
Elapsed time: 0.05485s