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.13.tar.gz (5.1 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.13-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fake_https_server-0.0.13.tar.gz
  • Upload date:
  • Size: 5.1 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.13.tar.gz
Algorithm Hash digest
SHA256 eafa5baaaffe545af5e76dca876446ce2da564991e80a15af7543f36b113d1c6
MD5 0449bf0886b195622c70c665b3643f69
BLAKE2b-256 421c6c3b716e12607c2b083120287c770972815ac1b41cfc2707d973ec322913

See more details on using hashes here.

Provenance

The following attestation bundles were made for fake_https_server-0.0.13.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.13-py3-none-any.whl.

File metadata

File hashes

Hashes for fake_https_server-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 980e8ee6512dd4358cd25ef6964e780c44cf7bcce052d5ee39b3d488c050e6ed
MD5 8590da2fc0a4c49c5ee2e6416e5dc134
BLAKE2b-256 b77d949257e506dc8ab92d678304dc91533cbeafd6a8ee5f88c5af95ba3a3984

See more details on using hashes here.

Provenance

The following attestation bundles were made for fake_https_server-0.0.13-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