Skip to main content

Fake http and https servers

Project description

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:

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

# 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

# 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fake_https_server-0.0.12.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fake_https_server-0.0.12-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file fake_https_server-0.0.12.tar.gz.

File metadata

  • Download URL: fake_https_server-0.0.12.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for fake_https_server-0.0.12.tar.gz
Algorithm Hash digest
SHA256 2e15e36f2ab8269f72d370d88eea40fec7abdf26e123b4cdf3d320e1aa39faed
MD5 891f35ecba93303bfac198b328e3754f
BLAKE2b-256 3c173d2f404fa9f8c2cd751bff872a7ff51975a48979a76b13835160d55d4068

See more details on using hashes here.

Provenance

The following attestation bundles were made for fake_https_server-0.0.12.tar.gz:

Publisher: python-release.yml on fabriciofx/fake-https-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fake_https_server-0.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for fake_https_server-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 d94ac71c758319e8af3ac76401a1e2e8de417565201b9c9b15618cf0a850a63c
MD5 9c9b1877de96091e859cc5f9627be27b
BLAKE2b-256 814d89ab0aec86caf52884bd78cb91e0db8dab22abc346254a2622cf134737ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for fake_https_server-0.0.12-py3-none-any.whl:

Publisher: python-release.yml on fabriciofx/fake-https-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page