# PyHTTPIntercept
Provides a HTTP Server which can be used to intercept and modify API requests/responses for local clients.
This is useful for client testing where generating different response types from the API is not always ideal.
The HTTP server provides the following functionality:
* Hosting of sites
* Redirecting requests with the following methods:
* HTTP 3xx statuses
* transparently to the client
* Intercepting and modifying of requests. Man-in-the-middle, useful for client testing against a production API.
* Proxying of requests
When a request comes in methods are checked & executed in the following order:
1. Redirect
2. Hosting
3. Intercept - Intercept will only be reached if request is not picked up by hosting.
4. Proxy - Proxy configuration will only be reached if request is not picked up by Hosting or Intercept.
---
## Hosting requests
Sites can be hosted as with any webserver. The server supports static sites/resources only.
### Hosting configuration
An example configuration file:
```JSON
{
"/": {
"doc_root": "default_sites/",
"active": true,
"description": "Root Site"
},
"/example": {
"doc_root": "default_sites/example/",
"active": true,
"description": "Example Site"
}
}
```
A configured site configurations key will be set to the expected url path.
Site configuration parameters:
* Object key: String - Path where site will be hosted.
* `doc_root`: String - The full path to the configured site. A relative path can also be configured and is explained below.
* `active`: Boolean - True if the site is to be served.
* `description`: String - [optional] A description for your site.
#### Relative paths
TODO
---
## Redirecting requests
### Sending HTTP 3xx statuses
These are your standard redirects.
### Transparently to the client
These are useful for clients that do not support redirects.
An example use would be redirecting a client with hard coded endpoints to a lab environemnt for testing without having to generate & install specific builds for the lab.
### Redirect configuration
Parameters:
* Object key: String - Domain to redirect.
* `host`: String - [optional] The full domain to redirect to.
* `paths`: Object - [optional] An object containing the paths being redirected for this domain.
* `active`: Boolean - True to enable redirect.
* `description`: String - [optional] A description for your redirect.
Note: at least one of `host` or `paths` must be specified!
Path object:
* Object key: String - Path to redirect.
* `host`: String - [optional] The full domain to redirect to.
* `path`: String - [optional] The full path to redirect to. If omitted then the path will be set to domain root.
* `status`: Number - [optional] The HTTP 3xx status to send. Specifying this parameter tells the server to use a HTTP 3xx redirect rather than redirecting transparently.
* `active`: Boolean - True to enable redirect.
* `description`: String - [optional] A description for your redirect.
Note: at least one of `path` or `host` (from either site/path config) must be specified!
If a host is specifed in the key it will only by honoured when intercepting or proxying, for anything else the keys will be ignored.
Redirecting paths within the same site:
```JSON
{
"example.com": {
"paths": {
"/example_redirect": {
"path": "/temp_path",
"active": true,
}
},
"active": true,
}
}
```
Redirecting paths within the same site using a HTTP 3xx redirect:
```JSON
{
"example.com": {
"paths": {
"/example_redirect": {
"path": "/temp_path",
"status": 301,
"active": true,
}
},
"active": true,
}
}
```
Redirecting paths from one site to another:
```JSON
{
"example.com": {
"host": "example2.com",
"paths": {
"/example_redirect": {
"path": "/",
"active": true,
}
},
"active": true,
}
}
```
This can also be done on a path by path basis:
```JSON
{
"example.com": {
"paths": {
"host": "example2.com",
"/example_redirect": {
"path": "/",
"active": true,
},
"/example_redirect2": {
"host": "example3.com",
"path": "/",
"active": true,
}
},
"active": true,
}
}
```
If a host is configured for a path it takes precedence over the site redirect host.
Redirecting one domain to another:
```JSON
{
"example.com": {
"host": "example2.com",
"active": true,
}
}
```
This applies to all paths for the domain.
---
## Intercepting requests
### Intercept configuration
Parameters:
* Object key: String - Domain to Intercept.
* `active`: Boolean - True to enable proxy.
* `description`: String - [optional] A description for your proxy.
An example configuration file:
```JSON
{
"example.com": {
"active": true,
"description": "Intercept & modify"
}
}
```
---
## Proxying requests
Parameters:
* Object key: String - Domain to proxy.
* `active`: Boolean - True to enable proxy.
* `description`: String - [optional] A description for your proxy.
Proxy can be configured to either proxy all requests:
```JSON
{
"*": {
"active": true,
"description": "Proxy All"
}
}
```
or specific domains only:
```JSON
{
"example.com": {
"active": true,
"description": "Proxy example.com"
}
}
```
---
## Wildcards
The '\*' character can be used as a wildcard.
### Domain wildcards
```*.example.com``` will handle requests for all subdomains, but not ```example.com```.
```*example.com``` will handle requests for all subdomains, including ```example.com```.
In the following example the first configuration ```example.com``` will only proxy requests for ```example.com```.
While the second configuration ```\*.example.com``` will proxy all subdomains but not ```example.com```.
```JSON
{
"example.com": {
"active": true,
"description": "Proxy example.com"
},
"*.example.com": {
"active": true,
"description": "Proxy subdomains of example.com"
}
}
```
This snippet can be simplified to:
```JSON
{
"*example.com": {
"active": true,
"description": "Proxy example.com and all subdomains"
}
}
```
### Path wildcards (Only available for redirects)
```/testing/*``` will redirect all requests for path ```/testing``` including sub paths i.e ```/testing/path_a```
In the following example ```example.com/example_redirect``` and all sub paths will be redirected to ```example.com/temp_path```.
```JSON
{
"example.com": {
"paths": {
"/example_redirect/*": {
"path": "/temp_path",
"active": true,
}
},
"active": true,
}
}
```
Raw data
{
"_id": null,
"home_page": "https://bitbucket.org/davisowb/pyhttpintercept.git",
"name": "pyhttpintercept",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pyhttpintercept",
"author": "Oli Davis & Hywel Thomas",
"author_email": "oli.davis@me.com, hywel.thomas@mac.com",
"download_url": "https://files.pythonhosted.org/packages/68/33/2abfd9d34e3797df6ba51aaaba0a30e6eb95144b90340511e27d9b6e5c10/pyhttpintercept-0.34.1.tar.gz",
"platform": null,
"description": "\n# PyHTTPIntercept\n\nProvides a HTTP Server which can be used to intercept and modify API requests/responses for local clients.\n\nThis is useful for client testing where generating different response types from the API is not always ideal.\n\nThe HTTP server provides the following functionality:\n\n* Hosting of sites\n* Redirecting requests with the following methods:\n * HTTP 3xx statuses\n * transparently to the client\n* Intercepting and modifying of requests. Man-in-the-middle, useful for client testing against a production API.\n* Proxying of requests\n\nWhen a request comes in methods are checked & executed in the following order:\n\n1. Redirect\n2. Hosting\n3. Intercept - Intercept will only be reached if request is not picked up by hosting.\n4. Proxy - Proxy configuration will only be reached if request is not picked up by Hosting or Intercept.\n\n\n---\n\n## Hosting requests\n\nSites can be hosted as with any webserver. The server supports static sites/resources only.\n\n### Hosting configuration\n\nAn example configuration file:\n\n```JSON\n{\n \"/\": {\n \"doc_root\": \"default_sites/\",\n \"active\": true,\n \"description\": \"Root Site\"\n },\n \"/example\": {\n \"doc_root\": \"default_sites/example/\",\n \"active\": true,\n \"description\": \"Example Site\"\n }\n}\n```\n\nA configured site configurations key will be set to the expected url path.\n\nSite configuration parameters:\n\n* Object key: String - Path where site will be hosted.\n* `doc_root`: String - The full path to the configured site. A relative path can also be configured and is explained below.\n* `active`: Boolean - True if the site is to be served.\n* `description`: String - [optional] A description for your site.\n\n#### Relative paths\nTODO\n\n\n---\n\n## Redirecting requests\n\n### Sending HTTP 3xx statuses\n\nThese are your standard redirects.\n\n### Transparently to the client\n\nThese are useful for clients that do not support redirects.\n\nAn example use would be redirecting a client with hard coded endpoints to a lab environemnt for testing without having to generate & install specific builds for the lab.\n\n### Redirect configuration\n\nParameters:\n\n* Object key: String - Domain to redirect.\n* `host`: String - [optional] The full domain to redirect to.\n* `paths`: Object - [optional] An object containing the paths being redirected for this domain.\n* `active`: Boolean - True to enable redirect.\n* `description`: String - [optional] A description for your redirect.\n\nNote: at least one of `host` or `paths` must be specified!\n\nPath object:\n\n* Object key: String - Path to redirect.\n* `host`: String - [optional] The full domain to redirect to.\n* `path`: String - [optional] The full path to redirect to. If omitted then the path will be set to domain root.\n* `status`: Number - [optional] The HTTP 3xx status to send. Specifying this parameter tells the server to use a HTTP 3xx redirect rather than redirecting transparently.\n* `active`: Boolean - True to enable redirect.\n* `description`: String - [optional] A description for your redirect.\n\nNote: at least one of `path` or `host` (from either site/path config) must be specified!\n\nIf a host is specifed in the key it will only by honoured when intercepting or proxying, for anything else the keys will be ignored.\n\nRedirecting paths within the same site:\n\n```JSON\n{\n \"example.com\": {\n \"paths\": {\n \"/example_redirect\": {\n \"path\": \"/temp_path\",\n \"active\": true,\n }\n },\n \"active\": true,\n }\n}\n```\n\nRedirecting paths within the same site using a HTTP 3xx redirect:\n\n```JSON\n{\n \"example.com\": {\n \"paths\": {\n \"/example_redirect\": {\n \"path\": \"/temp_path\",\n \"status\": 301,\n \"active\": true,\n }\n },\n \"active\": true,\n }\n}\n```\n\nRedirecting paths from one site to another:\n\n```JSON\n{\n \"example.com\": {\n \"host\": \"example2.com\",\n \"paths\": {\n \"/example_redirect\": {\n \"path\": \"/\",\n \"active\": true,\n }\n },\n \"active\": true,\n }\n}\n```\n\nThis can also be done on a path by path basis:\n\n```JSON\n{\n \"example.com\": {\n \"paths\": {\n \"host\": \"example2.com\",\n \"/example_redirect\": {\n \"path\": \"/\",\n \"active\": true,\n },\n \"/example_redirect2\": {\n \"host\": \"example3.com\",\n \"path\": \"/\",\n \"active\": true,\n }\n },\n \"active\": true,\n }\n}\n```\n\nIf a host is configured for a path it takes precedence over the site redirect host.\n\nRedirecting one domain to another:\n\n```JSON\n{\n \"example.com\": {\n \"host\": \"example2.com\",\n \"active\": true,\n }\n}\n```\n\nThis applies to all paths for the domain.\n\n\n---\n\n## Intercepting requests\n\n### Intercept configuration\n\nParameters:\n\n* Object key: String - Domain to Intercept.\n* `active`: Boolean - True to enable proxy.\n* `description`: String - [optional] A description for your proxy.\n\nAn example configuration file:\n\n```JSON\n{\n \"example.com\": {\n \"active\": true,\n \"description\": \"Intercept & modify\"\n }\n}\n```\n\n\n---\n\n## Proxying requests\n\nParameters:\n\n* Object key: String - Domain to proxy.\n* `active`: Boolean - True to enable proxy.\n* `description`: String - [optional] A description for your proxy.\n\nProxy can be configured to either proxy all requests:\n\n```JSON\n{\n \"*\": {\n \"active\": true,\n \"description\": \"Proxy All\"\n }\n}\n```\n\nor specific domains only:\n\n```JSON\n{\n \"example.com\": {\n \"active\": true,\n \"description\": \"Proxy example.com\"\n }\n}\n```\n\n\n---\n\n## Wildcards\n\nThe '\\*' character can be used as a wildcard.\n\n### Domain wildcards\n\n```*.example.com``` will handle requests for all subdomains, but not ```example.com```.\n```*example.com``` will handle requests for all subdomains, including ```example.com```.\n\nIn the following example the first configuration ```example.com``` will only proxy requests for ```example.com```.\nWhile the second configuration ```\\*.example.com``` will proxy all subdomains but not ```example.com```.\n\n```JSON\n{\n \"example.com\": {\n \"active\": true,\n \"description\": \"Proxy example.com\"\n },\n \"*.example.com\": {\n \"active\": true,\n \"description\": \"Proxy subdomains of example.com\"\n }\n}\n```\n\nThis snippet can be simplified to:\n\n```JSON\n{\n \"*example.com\": {\n \"active\": true,\n \"description\": \"Proxy example.com and all subdomains\"\n }\n}\n```\n\n\n### Path wildcards (Only available for redirects)\n\n```/testing/*``` will redirect all requests for path ```/testing``` including sub paths i.e ```/testing/path_a```\n\nIn the following example ```example.com/example_redirect``` and all sub paths will be redirected to ```example.com/temp_path```.\n\n```JSON\n{\n \"example.com\": {\n \"paths\": {\n \"/example_redirect/*\": {\n \"path\": \"/temp_path\",\n \"active\": true,\n }\n },\n \"active\": true,\n }\n}\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "",
"version": "0.34.1",
"split_keywords": [
"pyhttpintercept"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8a2201d7fc7e0d30ff86207eed7f01bd44529ee09826dd5f1ae0e92ffdee3896",
"md5": "3f664c62f06f0ddb234b5eb429344aa0",
"sha256": "f0d1c7059a3eca7f5b4ab1eeb1dae9ca3069e3f6dd52a4e39017fbf2a7f0991e"
},
"downloads": -1,
"filename": "pyhttpintercept-0.34.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "3f664c62f06f0ddb234b5eb429344aa0",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 961059,
"upload_time": "2023-01-27T18:09:56",
"upload_time_iso_8601": "2023-01-27T18:09:56.400672Z",
"url": "https://files.pythonhosted.org/packages/8a/22/01d7fc7e0d30ff86207eed7f01bd44529ee09826dd5f1ae0e92ffdee3896/pyhttpintercept-0.34.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "68332abfd9d34e3797df6ba51aaaba0a30e6eb95144b90340511e27d9b6e5c10",
"md5": "619042e29c5033d0203d78b61a8e2ed3",
"sha256": "307e09de9f8f52208ccd70248155ae97f1a3cb7be15c2708a11442b1cc79a025"
},
"downloads": -1,
"filename": "pyhttpintercept-0.34.1.tar.gz",
"has_sig": false,
"md5_digest": "619042e29c5033d0203d78b61a8e2ed3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 903730,
"upload_time": "2023-01-27T18:09:58",
"upload_time_iso_8601": "2023-01-27T18:09:58.852980Z",
"url": "https://files.pythonhosted.org/packages/68/33/2abfd9d34e3797df6ba51aaaba0a30e6eb95144b90340511e27d9b6e5c10/pyhttpintercept-0.34.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-27 18:09:58",
"github": false,
"gitlab": false,
"bitbucket": true,
"bitbucket_user": "davisowb",
"bitbucket_project": "pyhttpintercept.git",
"lcname": "pyhttpintercept"
}