docs: add crate README, MIT/Apache license files
- README covering the gateway surface, both import/export adapter families, feature flags, and security posture (all claims verified against the current code) - standard MIT and Apache-2.0 license texts matching the license = "MIT OR Apache-2.0" manifest field - Cargo.toml: point the manifest at README.md and exclude scripts/ from the published package
This commit is contained in:
@@ -5,10 +5,11 @@ edition = "2021"
|
||||
rust-version = "1.85"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "HTTP interface for the alk stack: serves HTTP/1.1 + HTTP/2 on standard ALPNs (with WebSocket upgrade carrying the channels protocol) and hosts the HTTP-backed call-protocol adapters"
|
||||
readme = "README.md"
|
||||
repository = "https://git.alk.dev/alkdev/alkhttp"
|
||||
keywords = ["http", "websocket", "rpc", "openapi", "mcp"]
|
||||
categories = ["network-programming", "web-programming", "asynchronous"]
|
||||
exclude = [".opencode/", "AGENTS.md", "docs/", "tasks/", "Cargo.lock"]
|
||||
exclude = [".opencode/", "AGENTS.md", "docs/", "tasks/", "scripts/", "Cargo.lock"]
|
||||
|
||||
[lib]
|
||||
name = "alkhttp"
|
||||
|
||||
192
LICENSE-APACHE
Normal file
192
LICENSE-APACHE
Normal file
@@ -0,0 +1,192 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name), or refer to, the Work.
|
||||
(Note: Derivative Works shall not include works that remain separable from,
|
||||
or merely link (or bind by name) to the interfaces of, the Work and
|
||||
Derivative Works thereof.)
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to the Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by the Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2025-2026 Alk Development
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
21
LICENSE-MIT
Normal file
21
LICENSE-MIT
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025-2026 Alk Development
|
||||
|
||||
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 NONINFRINGEMENT. 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.
|
||||
197
README.md
Normal file
197
README.md
Normal file
@@ -0,0 +1,197 @@
|
||||
# alkhttp
|
||||
|
||||
HTTP interface for the alk stack: serves HTTP/1.1 + HTTP/2 on standard
|
||||
ALPNs (with WebSocket upgrade carrying the channels protocol for browser
|
||||
bidirectional access) and hosts the HTTP-backed call-protocol adapters.
|
||||
|
||||
alkhttp wraps [`alkcall`](https://crates.io/crates/alkcall) — the pure
|
||||
call + channels protocol crate — and turns its operation registry into
|
||||
an HTTP surface. It is the HTTP server host (a `ProtocolHandler` for the
|
||||
IANA `h2`/`http/1.1` ALPNs) and the HTTP client host (the import
|
||||
adapters that call out over `reqwest`) in one crate.
|
||||
|
||||
## What's inside
|
||||
|
||||
**Server side (`server` feature)** — the producer-facing HTTP surface:
|
||||
|
||||
- `HttpAdapter` — an axum `Router` driven by hyper's HTTP/1.1 and HTTP/2
|
||||
connection handling over a `BiStream`, served on standard ALPNs so any
|
||||
HTTP client connects without knowing about the alk stack.
|
||||
- Six fixed gateway endpoints — the sole HTTP invoke path (no
|
||||
per-operation REST tree):
|
||||
`GET /search`, `GET /schema?name=…`, `POST /call`, `POST /batch`,
|
||||
`POST /subscribe` (SSE), `POST /publish` (NDJSON).
|
||||
- `/healthz`, `/openapi.json` (a `to_openapi` projection of the local
|
||||
registry), and `/mcp` (the MCP tool gateway, feature `mcp`).
|
||||
- WebSocket upgrade on `/alk/channels` carrying the channels protocol:
|
||||
8-byte chunk multiplexing with channel 0 pre-negotiated as `alk/call`,
|
||||
so a browser runs the native bidirectional call-protocol session.
|
||||
- Bearer auth, a stealth decoy surface for unknown paths, custom-route
|
||||
mounting, and assembly hooks for WS session caps and timeouts.
|
||||
|
||||
**Client side (`client` feature)** — the consumer-facing import
|
||||
adapters, each producing ordinary `HandlerRegistration` bundles for an
|
||||
`alkcall` registry:
|
||||
|
||||
- `from_openapi` — import an external HTTP API described by an OpenAPI
|
||||
document (JSON or YAML), forwarding calls over the shared reqwest
|
||||
client.
|
||||
- `from_jsonschema` — import one non-OpenAPI HTTP endpoint behind a
|
||||
caller-built `OperationSpec`.
|
||||
- `from_mcp` — import a remote MCP server's tools as operations over
|
||||
streamable HTTP (feature `mcp`).
|
||||
- `from_wss` — import a remote alk node's operations over a WSS
|
||||
channels connection (feature `wss`).
|
||||
- `SharedHttpClient` — the hot-reloadable reqwest stack all `from_*`
|
||||
forwarding rides: same-host-only redirects, idempotent-only retries
|
||||
with a wall-clock budget, `Retry-After` support, TLS config, and
|
||||
streaming byte caps.
|
||||
|
||||
**Both sides (`openapi` feature, implied)** — the shared OpenAPI
|
||||
document model plus the reverse projections `to_openapi` (generate the
|
||||
gateway's OpenAPI document from the registry) and `to_mcp` (expose local
|
||||
operations as MCP tools).
|
||||
|
||||
## Quick start
|
||||
|
||||
### Serve the gateway over HTTP
|
||||
|
||||
`HttpAdapter` implements alkcall's `ProtocolHandler`; the endpoint /
|
||||
accept loop is the consumer's concern (dial and TLS live downstream).
|
||||
Wire it for the ALPN you serve and drive it with your connection source:
|
||||
|
||||
```rust
|
||||
use std::sync::Arc;
|
||||
|
||||
use alkcall::core::auth::IdentityProvider;
|
||||
use alkcall::core::types::Connection;
|
||||
use alkcall::registry::registration::OperationRegistry;
|
||||
use alkhttp::server::{DecoyConfig, HttpAdapter};
|
||||
|
||||
let registry = Arc::new(OperationRegistry::new());
|
||||
let provider: Arc<dyn IdentityProvider> = /* your identity provider */;
|
||||
|
||||
let adapter = HttpAdapter::h2(provider, registry)
|
||||
.with_decoy(DecoyConfig::NotFound);
|
||||
|
||||
// adapter.alpn() == b"h2" — register it in your handler registry for
|
||||
// that ALPN; each accepted Connection is handled by
|
||||
// ProtocolHandler::handle(&adapter, connection, &auth).
|
||||
```
|
||||
|
||||
Once wired, HTTP callers get the fixed gateway surface. Discovery is
|
||||
per-caller, filtered by `AccessControl`:
|
||||
|
||||
```text
|
||||
GET /search → { "request_id": …, "result": "ok",
|
||||
"output": { "operations": [ … ] } }
|
||||
GET /schema?name=fs/readFile → the operation's input/output schema
|
||||
POST /call ← { "operation": "fs/readFile",
|
||||
"input": { … } }
|
||||
POST /batch ← [ { "operation": …, "input": … }, … ]
|
||||
POST /subscribe → SSE stream of call-protocol envelopes
|
||||
POST /publish ← NDJSON body of published chunks
|
||||
```
|
||||
|
||||
`/openapi.json` serves the same surface as an OpenAPI document, so
|
||||
standard tooling can drive the gateway without knowing the alk stack.
|
||||
|
||||
### Import an OpenAPI-described API
|
||||
|
||||
```rust
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use alkhttp::adapters::{FromOpenAPI, HttpServiceConfig, OpenAPISpec};
|
||||
use alkhttp::client::{HttpClientConfig, SharedHttpClient};
|
||||
|
||||
let doc = r#"{"openapi":"3.0.0","info":{"title":"Widgets","version":"1"},
|
||||
"paths":{"/widgets":{"get":{"operationId":"listWidgets",
|
||||
"responses":{"200":{"content":{"application/json":{"schema":{}}}}}}}}}"#;
|
||||
|
||||
let spec = OpenAPISpec::from_json(doc)?;
|
||||
let config = HttpServiceConfig {
|
||||
namespace: "widgets".to_string(),
|
||||
base_url: "https://widgets.example.com".to_string(),
|
||||
auth: None, // or Some(HttpAuthScheme::Bearer) — the credential is
|
||||
// injected per-call from Capabilities, never from config
|
||||
default_headers: HashMap::new(),
|
||||
};
|
||||
let http_client = Arc::new(SharedHttpClient::new(HttpClientConfig::default())?);
|
||||
|
||||
let adapter = FromOpenAPI::new(spec, config, http_client);
|
||||
let registrations = alkcall::client::OperationAdapter::import(&adapter).await?;
|
||||
|
||||
let mut registry = alkcall::registry::registration::OperationRegistry::new();
|
||||
for reg in registrations {
|
||||
registry.register(reg)?;
|
||||
}
|
||||
// "widgets/listWidgets" is now callable — and composable — through the
|
||||
// call protocol and the gateway.
|
||||
```
|
||||
|
||||
Imported operations register `Visibility::Internal` (they are
|
||||
composition material); an External facade op composed over them via
|
||||
`ctx.env.invoke` is what the wire sees.
|
||||
|
||||
### WebSocket for browsers
|
||||
|
||||
A browser upgrades `GET /alk/channels` (Bearer token in the
|
||||
`Authorization` header) to a WebSocket and speaks the channels protocol
|
||||
in binary messages: an 8-byte chunk header multiplexes N channels;
|
||||
channel 0 is pre-negotiated as `alk/call` and runs the native
|
||||
call-protocol session. Both sides can initiate calls; the browser can
|
||||
also register operations and open channels — it is a full consumer and
|
||||
producer on its own connection-local overlay.
|
||||
|
||||
## Feature flags
|
||||
|
||||
The crate is feature-sided — build one side, or both:
|
||||
|
||||
| Feature | Default | Gates |
|
||||
|---------|---------|-------|
|
||||
| `server` | yes | the axum host, gateway routes, WS upgrade, `/healthz`, `/openapi.json`, `to_openapi` |
|
||||
| `client` | yes | the shared outbound client host, `from_openapi`, `from_jsonschema` |
|
||||
| `openapi` | (implied) | the shared OpenAPI document model (implied by both sides) |
|
||||
| `mcp` | no | `from_mcp` (needs `client`) and `to_mcp` (needs `server`) |
|
||||
| `wss` | no | the `from_wss` consumer adapter |
|
||||
| `h2`, `http1` | yes | the server's HTTP protocol features (imply `server`) |
|
||||
|
||||
A lean single-side build takes `default-features = false` plus the side
|
||||
it needs:
|
||||
|
||||
```toml
|
||||
alkhttp = { version = "0.1", default-features = false, features = ["server"] }
|
||||
```
|
||||
|
||||
## Security posture
|
||||
|
||||
- **No secret material on the wire.** Request/response payloads and
|
||||
headers carry no keys or tokens beyond the caller's own Bearer
|
||||
credential. Outbound credentials flow vault → assembly layer →
|
||||
`Capabilities` → handler; the `from_*` adapters are the injection
|
||||
point, and no handler reads `std::env::var`.
|
||||
- **Stealth mode.** The HTTP surface serves on standard ALPNs, and
|
||||
unregistered paths answer with a configurable decoy (fake nginx 404,
|
||||
static site, or redirect) instead of advertising the gateway.
|
||||
- **Tight forwarding defaults.** Same-host-only redirects,
|
||||
idempotent-only retries with a wall-clock budget and `Retry-After`
|
||||
ceiling, 30 s request / 10 s connect / 30 s read timeouts, a 2 MiB
|
||||
gateway body cap (8 MiB on `/mcp`), and a 1 GiB streamed-bytes cap per
|
||||
subscription.
|
||||
- **Internal-by-default imports.** Adapter-registered operations are
|
||||
invisible to direct wire calls (`NOT_FOUND`) until composed behind an
|
||||
External facade.
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Architecture docs](docs/architecture/README.md) — the authoritative
|
||||
spec: ADRs 001–071, component documents, and open questions.
|
||||
- [API docs](https://docs.rs/alkhttp) — full crate documentation on
|
||||
docs.rs.
|
||||
- [Changelog](CHANGELOG.md)
|
||||
|
||||
## License
|
||||
|
||||
MIT OR Apache-2.0 — see [LICENSE-MIT](LICENSE-MIT) and
|
||||
[LICENSE-APACHE](LICENSE-APACHE).
|
||||
Reference in New Issue
Block a user