Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade to hyper 1.1 #1

Merged
merged 32 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3f3a2e4
Switch from pin-project to pin-project-lite
onalante-msft Jan 7, 2022
f6b4ccd
Match hyperlocal features with hyper features
onalante-msft Jan 7, 2022
4618d6e
Remove unused futures-util features
onalante-msft Jan 7, 2022
c95ce37
Remove futures-util dependency
onalante-msft Jan 7, 2022
7a2cbb8
Merge pull request #54 from onalante-msft/main
softprops Jan 10, 2022
f185a48
Add and fix clippy lints and formatting errors
onalante-msft Jan 10, 2022
b29beff
Update GitHub workflows to use all features
onalante-msft Jan 10, 2022
2ee4d14
Merge pull request #55 from onalante-msft/misc-clippy
softprops Jan 11, 2022
b91ded3
export `UnixStream` for clients
fnichol Oct 21, 2021
cee7961
Add rustdoc for UnixStream
onalante-msft Aug 13, 2022
fe34a47
Adding support for UnixStream to take advantage of vectored writes wh…
craftytrickster Oct 28, 2023
22f53f9
Upgrade hyper to 1.1
iamjpotts Jan 7, 2024
34dc857
Merge pull request #65 from iamjpotts/202401-hyper-1.0
softprops Jan 15, 2024
70c0b8e
release prep
softprops Mar 8, 2024
0596ef9
Examples: Add additional logging of accepted connections
iamjpotts Mar 19, 2024
09f9806
Merge pull request #67 from iamjpotts/20240319-improve-example
softprops Mar 19, 2024
bf06e28
Disable keep-alive on server example
iamjpotts Apr 7, 2024
adf3588
Merge pull request #68 from iamjpotts/20240407-server-example-keepalive
softprops Apr 7, 2024
6409d89
delete dup rustfmt config file and resolve rustfmt depr warnings. fix…
softprops May 5, 2024
464dd26
Update readme to reflect lack of server extension trait after upgrade…
iamjpotts Jun 10, 2024
e8a6ff2
Merge pull request #73 from iamjpotts/20240609-update-docs
softprops Jun 10, 2024
8e2979e
Add server extension trait revised for hyper 1.x
iamjpotts Jun 10, 2024
703fd91
Merge pull request #72 from iamjpotts/20240609-update-server
softprops Jun 11, 2024
ab837c4
Merge pull request #63 from craftytrickster/unix-socket-vectored-writes
softprops Jul 22, 2024
6d3e2a6
update changelog
softprops Jul 22, 2024
dafdcdf
Merge pull request #60 from onalante-msft/pub-unix-stream
softprops Jul 22, 2024
b8b75dc
update changelog
softprops Jul 22, 2024
d4b04ae
fix broken vectorization pull
softprops Jul 22, 2024
720d1c9
reset version because previous workflow run failed to faulty pull
softprops Jul 22, 2024
e0323e6
fix readme
softprops Jul 22, 2024
aa7bb12
maint
softprops Jul 22, 2024
a579ece
Merge remote-tracking branch 'upstream/main'
CompuIves Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
with:
rust-version: ${{ matrix.rust }}
- name: Test
run: cargo test
run: cargo test --all-features

publish-docs:
if: github.ref == 'refs/heads/main'
Expand All @@ -97,7 +97,7 @@ jobs:
- uses: actions/checkout@v2
- name: Generate Docs
run: |
cargo doc --no-deps
cargo doc --no-deps --all-features
echo "<meta http-equiv=refresh content=0;url=`echo ${{ github.repository }} | cut -d / -f 2 | tr '-' '_'`/index.html>" > target/doc/index.html
- name: Publish
uses: peaceiris/actions-gh-pages@v3
Expand All @@ -118,4 +118,4 @@ jobs:
shell: bash
run: cargo publish --token ${{ env.CRATES_TOKEN }}
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
5 changes: 0 additions & 5 deletions .rustfmt.toml

This file was deleted.

53 changes: 31 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
# 0.9.1

- Export UnixStream for clients [#60](https://github.com/softprops/hyperlocal/pull/60) via [@onalante-msft](https://github.com/onalante-msft)
- Adding support for UnixStream to take advantage of vectored writes [#63](https://github.com/softprops/hyperlocal/pull/63) via [@craftytrickster](https://github.com/craftytrickster)

# 0.9.0

- upgrade to hyper 1.1 [#65](https://github.com/softprops/hyperlocal/pull/65) via [iamjpotts](https://github.com/iamjpotts)

# 0.8.0

* upgrade to tokio 1.0 and hyper 0.14 [#44](https://github.com/softprops/hyperlocal/pull/44)
* port ci from Travis CI to GitHub Actions
* `main` is the new default GitHub branch
- upgrade to tokio 1.0 and hyper 0.14 [#44](https://github.com/softprops/hyperlocal/pull/44)
- port ci from Travis CI to GitHub Actions
- `main` is the new default GitHub branch

# 0.7.0

* reimplement server for `std::future` (`async`/`await`)
* upgrade to tokio 0.2
* add `SocketIncoming` interface
- reimplement server for `std::future` (`async`/`await`)
- upgrade to tokio 0.2
- add `SocketIncoming` interface

# 0.6.0

* upgrade to hyper 0.13
* upgrade hex to 0.3 [#15](https://github.com/softprops/hyperlocal/pull/15)
* move from tokio-core to tokio 0.1 [#16](https://github.com/softprops/hyperlocal/pull/16)
* don't explicitly block on unix socket connection [#18](https://github.com/softprops/hyperlocal/pull/18)
* provide a more flexible set of Server interfaces and to align more closely with those of hyper's default server bindings [#19](https://github.com/softprops/hyperlocal/pull/19)
- upgrade to hyper 0.13
- upgrade hex to 0.3 [#15](https://github.com/softprops/hyperlocal/pull/15)
- move from tokio-core to tokio 0.1 [#16](https://github.com/softprops/hyperlocal/pull/16)
- don't explicitly block on unix socket connection [#18](https://github.com/softprops/hyperlocal/pull/18)
- provide a more flexible set of Server interfaces and to align more closely with those of hyper's default server bindings [#19](https://github.com/softprops/hyperlocal/pull/19)

You'll want to use `hyperlocal::server::Server` where you would have used `hyperlocal::server::Http` in the past and use
`hyperlocal::server::Http` for a lower level interfaces that give you more control over "driving" your server.

# 0.5.0

* upgrade to hyper 0.12 [#11](https://github.com/softprops/hyperlocal/pull/11)
* expose the [SocketAddr](https://doc.rust-lang.org/std/os/unix/net/struct.SocketAddr.html) servers listen on with `Server#local_addr`
- upgrade to hyper 0.12 [#11](https://github.com/softprops/hyperlocal/pull/11)
- expose the [SocketAddr](https://doc.rust-lang.org/std/os/unix/net/struct.SocketAddr.html) servers listen on with `Server#local_addr`

# 0.4.1

* implement Clone for `UnixConnector` [@letmutx](https://github.com/softprops/hyperlocal/pull/7)
- implement Clone for `UnixConnector` [@letmutx](https://github.com/softprops/hyperlocal/pull/7)

# 0.4.0

* refactor for async hyper
* `hyperlocal::DomainUrl` is now `hyperlocal::Uri` the semantics are the same but the name now matches hyper's new name can can be lifted into hypers type
- refactor for async hyper
- `hyperlocal::DomainUrl` is now `hyperlocal::Uri` the semantics are the same but the name now matches hyper's new name can can be lifted into hypers type

```rust
let uri: hyper:Uri =
Expand All @@ -42,18 +51,18 @@ let uri: hyper:Uri =
"/foo/bar?baz=boom"
).into();
```
* `hyperlocal::UnitSocketConnector` is now just `hyperlocal::UnixConnector` to be more inline with the naming conventions behind`hyper::HttpConnector` and `hyper_tls::HttpsConnector`
* `hyperlocal::UnixSocketServer` is now `hyperlocal::server::Http` to be more inline with hyper naming conventions

- `hyperlocal::UnitSocketConnector` is now just `hyperlocal::UnixConnector` to be more inline with the naming conventions behind`hyper::HttpConnector` and `hyper_tls::HttpsConnector`
- `hyperlocal::UnixSocketServer` is now `hyperlocal::server::Http` to be more inline with hyper naming conventions

# 0.3.0

* enable using unix_socket from stdlib. [#4](https://github.com/softprops/hyperlocal/pull/4)
* upgrade to hyper 0.10
- enable using unix_socket from stdlib. [#4](https://github.com/softprops/hyperlocal/pull/4)
- upgrade to hyper 0.10

# 0.2.0

* upgraded to hyper 0.9 and transitively url 1.0

- upgraded to hyper 0.9 and transitively url 1.0

# 0.1.0

Expand Down
46 changes: 37 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
[package]
name = "hyperlocal"
version = "0.8.0"
version = "0.9.1"
authors = ["softprops <d.tangren@gmail.com>"]
description = "Hyper bindings for Unix domain sockets"
homepage = "https://github.com/softprops/hyperlocal"
repository = "https://github.com/softprops/hyperlocal"
keywords = ["hyper", "unix", "sockets", "http"]
license = "MIT"
readme = "README.md"
edition = "2018"
edition = "2021"

[dependencies]
hex = "0.4"
hyper = { version = "0.14", features = ["server", "client", "http1", "runtime"] }
tokio = { version = "1.0", features = ["rt-multi-thread", "net"] }
pin-project = "1.0"
futures-util = "0.3"
http-body-util = { version = "0.1", optional = true }
hyper = "1.3"
hyper-util = { version = "0.1.2", optional = true }
tokio = { version = "1.35", default-features = false, features = ["net"] }
tower-service = { version = "0.3", optional = true }
pin-project-lite = "0.2"

[dev-dependencies]
tokio = { version = "1.0", features = ["rt-multi-thread", "net", "macros", "io-std", "io-util"] }
thiserror = "1.0"
tokio = { version = "1.35", features = [
"io-std",
"io-util",
"macros",
"rt-multi-thread",
] }

[features]
client = []
server = []
default = ["client", "server"]
client = [
"http-body-util",
"hyper/client",
"hyper/http1",
"hyper-util/client-legacy",
"hyper-util/http1",
"hyper-util/tokio",
"tower-service",
]
server = ["hyper/http1", "hyper/server", "hyper-util/tokio"]

[[example]]
name = "client"
required-features = ["client"]

[[example]]
name = "server"
required-features = ["server"]

[[test]]
name = "server_client"
required-features = ["client", "server"]
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015-2020 Doug Tangren
Copyright (c) 2015-2024 Doug Tangren

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -17,4 +17,4 @@ 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.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76 changes: 15 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div align="center">
🔌 ✨
🔌 ✨

</div>

<h1 align="center">
Expand Down Expand Up @@ -40,55 +41,28 @@ want to limit access to the current host, in which case, opening and exposing tc
not needed. Examples of Unix daemons that provide this kind of host local interface include
[Docker](https://docs.docker.com/engine/misc/), a process container manager.


## Installation

Add the following to your `Cargo.toml` file

```toml
[dependencies]
hyperlocal = "0.8"
hyperlocal = "0.9"
```

## Usage

### Servers

A typical server can be built with `hyperlocal::server::UnixServerExt`.

```rust
use std::{error::Error, fs, path::Path};
use hyper::{
service::{make_service_fn, service_fn},
Body, Response, Server,
};
use hyperlocal::UnixServerExt;

const PHRASE: &str = "It's a Unix system. I know this.";

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let path = Path::new("/tmp/hyperlocal.sock");

if path.exists() {
fs::remove_file(path)?;
}

let make_service = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(|_req| async {
Ok::<_, hyper::Error>(Response::new(Body::from(PHRASE)))
}))
});

Server::bind_unix(path)?.serve(make_service).await?;
A typical server can be built by creating a `tokio::net::UnixListener` and accepting connections in a loop using
`hyper::service::service_fn` to create a request/response processing function, and connecting the `UnixStream` to it
using `hyper::server::conn::http1::Builder::new().serve_connection()`.

Ok(())
}
`hyperlocal` provides an extension trait `UnixListenerExt` with an implementation of this.

```

To test that your server is working you can use an out of the box tool like `curl`
An example is at [examples/server.rs](./examples/server.rs), runnable via `cargo run --example server`

To test that your server is working you can use an out-of-the-box tool like `curl`

```sh
$ curl --unix-socket /tmp/hyperlocal.sock localhost
Expand All @@ -98,38 +72,18 @@ It's a Unix system. I know this.

### Clients

`hyperlocal` also provides bindings for writing unix domain socket based HTTP clients using `Hyper`'s native `Client` interface.
`hyperlocal` also provides bindings for writing unix domain socket based HTTP clients the `Client` interface from the
`hyper-utils` crate.

Configure your `Hyper` client using `hyper::Client::builder()`.
An example is at [examples/client.rs](./examples/client.rs), runnable via `cargo run --example client`

Hyper's client interface makes it easy to send typical HTTP methods like `GET`, `POST`, `DELETE` with factory
methods, `get`, `post`, `delete`, etc. These require an argument that can be tranformed into a `hyper::Uri`.
methods, `get`, `post`, `delete`, etc. These require an argument that can be transformed into a `hyper::Uri`.

Since Unix domain sockets aren't represented with hostnames that resolve to ip addresses coupled with network ports,
your standard over the counter URL string won't do. Instead, use a `hyperlocal::Uri`, which represents both file path to the domain
socket and the resource URI path and query string.

```rust
use std::error::Error;
use hyper::{body::HttpBody, Client};
use hyperlocal::{UnixClientExt, Uri};
use tokio::io::{self, AsyncWriteExt as _};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let url = Uri::new("/tmp/hyperlocal.sock", "/").into();

let client = Client::unix();

let mut response = client.get(url).await?;

while let Some(next) = response.data().await {
let chunk = next?;
io::stdout().write_all(&chunk).await?;
}

Ok(())
}
```
---

Doug Tangren (softprops) 2015-2020
Doug Tangren (softprops) 2015-2024
17 changes: 11 additions & 6 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use hyper::{body::HttpBody, Client};
use hyperlocal::{UnixClientExt, Uri};
use http_body_util::{BodyExt, Full};
use hyper::body::Bytes;
use hyper_util::client::legacy::Client;
use hyperlocal::{UnixClientExt, UnixConnector, Uri};
use std::error::Error;
use tokio::io::{self, AsyncWriteExt as _};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let url = Uri::new("/tmp/hyperlocal.sock", "/").into();

let client = Client::unix();
let client: Client<UnixConnector, Full<Bytes>> = Client::unix();

let mut response = client.get(url).await?;

while let Some(next) = response.data().await {
let chunk = next?;
io::stdout().write_all(&chunk).await?;
while let Some(frame_result) = response.frame().await {
let frame = frame_result?;

if let Some(segment) = frame.data_ref() {
io::stdout().write_all(segment.iter().as_slice()).await?;
}
}

Ok(())
Expand Down
32 changes: 20 additions & 12 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use hyper::{
service::{make_service_fn, service_fn},
Body, Response, Server,
};
use hyperlocal::UnixServerExt;
use std::{error::Error, fs, path::Path};

const PHRASE: &str = "It's a Unix system. I know this.";
use hyper::Response;
use tokio::net::UnixListener;

use hyperlocal::UnixListenerExt;

const PHRASE: &str = "It's a Unix system. I know this.\n";

// Adapted from https://hyper.rs/guides/1/server/hello-world/
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let path = Path::new("/tmp/hyperlocal.sock");
Expand All @@ -15,13 +16,20 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
fs::remove_file(path)?;
}

let make_service = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(|_req| async {
Ok::<_, hyper::Error>(Response::new(Body::from(PHRASE)))
}))
});
let listener = UnixListener::bind(path)?;

println!("Listening for connections at {}.", path.display());

listener
.serve(|| {
println!("Accepted connection.");

Server::bind_unix(path)?.serve(make_service).await?;
|_request| async {
let body = PHRASE.to_string();
Ok::<_, hyper::Error>(Response::new(body))
}
})
.await?;

Ok(())
}
Loading
Loading