Metadata-Version: 2.4
Name: fake-https-server
Version: 0.0.9
Summary: Fake http and https servers
Author-email: Fabrício Barros Cabral <fabriciofx@gmail.com>
License-Expression: MIT
Project-URL: homepage, https://github.com/fabriciofx/fake_https_server
Project-URL: bug-tracker, https://github.com/fabriciofx/fake_https_server/issues
Keywords: fake,mock,http,https,server,request
Requires-Python: >=3.14
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: random-port>=0.0.5
Dynamic: license-file

# Fake Https Server

## Introduction

Fake Https Server is a package to create auto assigned HTTPS and HTTP servers to
use with tests. Useful to tests web scrapers and https or https clients.

## How create auto assigned certificates

Follow `docs/receita-servidor-cliente-ssl.md` recipe.

## How to use

Install it using `pip` command:

```bash
pip install fake_https_server
```

in your project folder.

## Usage

First, generate the server and ca certificates. To do it, follow the recipe.
Then, you can use HTTP or HTTPS server as follow:

### Fake HTTP Server

```python
# Message to be sent
msg = "It works"
# Create the fake HTTP server. By default the HTTP server will listen at
# localhost, a random free port (between 1024 and 65535)
server = Daemon(FakeHttpServer(ContentGet(msg)))
# Start the server
server.start()
# Make a http client connection to the server
client = http.client.HTTPConnection("localhost", server.port())
client.request("GET", "/")
# Get the server response
response = client.getresponse()
content = response.read().decode()
# Stop the fake http server
server.stop()
```

### Fake HTTPS Server

```python
# Path to ca certificate file (the https client needs it)
ca_file = Path(__file__).parent.parent / "certificates" / "ca.crt"
# Message to be sent
msg = "It works!"
# Create the fake HTTPS server. By default the HTTPS server will listen at
# localhost, a random free port (between 1024 and 65535)
server = Daemon(FakeHttpsServer(ContentGet(msg)))
# Start the server
server.start()
# Make a https client connection to the server
client = http.client.HTTPSConnection(
    "localhost",
    server.port(),
    context=ssl.create_default_context(cafile=ca_file)
)
client.request("GET", "/")
# Get the server response
response = client.getresponse()
content = response.read().decode()
# Stop the fake http server
server.stop()
```

## License

The MIT License (MIT)

Copyright (C) 2025 Fabrício Barros Cabral

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
