-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
- Loading branch information
Showing
6 changed files
with
81 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from http.server import SimpleHTTPRequestHandler, HTTPServer | ||
import sys | ||
|
||
|
||
class EchoHandler(SimpleHTTPRequestHandler): | ||
def log_message(self, format, *args): | ||
# Write logs to stdout instead of stderr | ||
log_entry = "[%s] %s\n" % (self.log_date_time_string(), format % args) | ||
sys.stdout.write(log_entry) | ||
|
||
def _set_headers(self): | ||
self.send_response(200) | ||
self.send_header('Content-type', 'text/plain') | ||
self.end_headers() | ||
|
||
def do_POST(self): | ||
content_length = int(self.headers['Content-Length']) | ||
body = self.rfile.read(content_length) | ||
self._set_headers() | ||
self.wfile.write(body) | ||
|
||
|
||
def run(port=8080): | ||
server_address = ('', port) | ||
httpd = HTTPServer(server_address, EchoHandler) | ||
print(f'Starting server on port {port}...') | ||
httpd.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
http-echo.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
spin_manifest_version = 2 | ||
|
||
[application] | ||
name = "wasi-http" | ||
authors = ["Fermyon Engineering <engineering@fermyon.com>"] | ||
version = "0.1.0" | ||
|
||
[[trigger.http]] | ||
route = "/" | ||
component = "test" | ||
|
||
[component.test] | ||
source = "{{wasi-http-v0.2.0-rc-2023-11-10}}" | ||
allowed_outbound_hosts = ["http://localhost:8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
tests/test-components/components/wasi-http-v0.2.0-rc-2023-11-10/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
The `wasi_snapshot_preview1.reactor.wasm` file in this directory was retrieved | ||
using: | ||
# Wasi HTTP (v0.2.0-rc-2023-11-10) | ||
|
||
``` | ||
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v15.0.1/wasi_snapshot_preview1.reactor.wasm | ||
``` | ||
Tests the Wasi HTTP outgoing request handler specifically the 0.2.0-rc-2023-11-10 version. | ||
|
||
The `wit` directory was copied from https://github.com/bytecodealliance/wasmtime/tree/v15.0.1/crates/wasi/wit | ||
The `wit` directory was copied from https://github.com/bytecodealliance/wasmtime/tree/v15.0.1/crates/wasi/wit and then modified to only include the parts actually used by this component. | ||
|
||
## Expectations | ||
|
||
This test component expects the following to be true: | ||
* It has access to an HTTP server on localhost:8080 that accepts POST requests and returns the same bytes in the response body as in the request body. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters