profile
viewpoint
Jeremiah Senkpiel Fishrock123 hire me to do Rust!! Unceded Sḵwx̱wú7mesh Úxwumixw territory www.jeremiah-senkpiel.com Indie game dev, Rust dev, former Node.js TSC member — he or they

AndreasMadsen/dprof 72

Dynamic/structured profiling & visualization for sync and async operations

Fishrock123/bob 67

🚰 binary data "streams+" via data producers, data consumers, and pull flow.

Fishrock123/beautify-benchmark 29

Beautify Benchmark.js's output into readable form.

Fishrock123/asteroids-webgl 2

My first actually published game, developed in late 2017 as an easter egg within N|Solid.

Fishrock123/ayo 1

It's pronounced like "IO" would be in English

Fishrock123/build 1

Better build and test infra for Node.

Fishrock123/cli-status 1

Highly configurable status indicators for your node.js cli.

Fishrock123/api-cdi 0

Collaborative Development Initiative for Public APIs

Fishrock123/async-h1 0

Asynchronous HTTP/1.1 in Rust

Pull request review commenthttp-rs/async-session

get async-session working with tide

+//! In-memory session store.+use async_std::io::{Error, ErrorKind};+use async_std::sync::{Arc, RwLock};+use http_types::cookies::Cookie;+use std::collections::HashMap;++use async_trait::async_trait;+use uuid::Uuid;++use crate::{Session, SessionStore};++/// An in-memory session store.+///+/// # Security+///+/// This store *does not* generate secure sessions, and should under no+/// circumstance be used in production. It's meant only to quickly create+/// sessions.+#[derive(Debug, Clone)]+pub struct MemoryStore {+    inner: Arc<RwLock<HashMap<String, Session>>>,+}++impl MemoryStore {+    /// Create a new instance of MemoryStore.+    pub fn new() -> Self {+        Self {+            inner: Arc::new(RwLock::new(HashMap::new())),+        }+    }+}++#[async_trait]+impl SessionStore for MemoryStore {+    /// The type of error that can occur when storing and loading errors.+    type Error = std::io::Error;++    /// Get a session from the storage backend.+    async fn load_session(&self, cookie: Cookie<'_>) -> Result<Option<Session>, Self::Error> {+        let id = Uuid::parse_str(cookie.value())+            .map_err(|_| Error::new(ErrorKind::Other, "Cookie content was not a valid uuid"))?+            .to_string();++        let inner = self.inner.read().await;+        Ok(inner.get(&id).cloned())+    }++    /// Store a session on the storage backend.+    ///+    /// The data inside the session will be url-encoded so it can be stored+    /// inside a cookie.+    async fn store_session(&self, session: Session) -> Result<String, Self::Error> {+        let mut inner = self.inner.write().await;+        let id = session.get("id").unwrap().to_string();

Why have it return a result then rather than just having an implementer panic internally?

jbr

comment created time in an hour

pull request commenthttp-rs/tide

tide sessions

We should probably also provide a CookieSession by default.

jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+use crate::Session;+use async_trait::async_trait;+use http_types::cookies::Cookie;++/// An async session backend.+#[async_trait]+pub trait SessionStore: Send + Sync + 'static + Clone {+    /// The type of error that can occur when storing and loading errors.+    type Error: std::error::Error + Send + Sync + 'static;

Why not make this always be http_types::Error? Since we're probably going to require a conversion in the end anyways it may be best to just let implementers handle any conversions. (Similar to http_client::HttpClient recently.)

jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+use crate::Session;+use async_trait::async_trait;+use http_types::cookies::Cookie;++/// An async session backend.+#[async_trait]+pub trait SessionStore: Send + Sync + 'static + Clone {+    /// The type of error that can occur when storing and loading errors.+    type Error: std::error::Error + Send + Sync + 'static;++    /// Get a session from the storage backend.+    ///+    /// The input should usually be the content of a cookie. This will then be+    /// parsed by the session middleware into a valid session.+    async fn load_session(&self, cookie: Cookie<'_>) -> Result<Option<Session>, Self::Error>;++    /// Store a session on the storage backend.+    ///+    async fn store_session(&self, session: Session) -> Result<String, Self::Error>;

What is Ok(String) here?

jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+use serde::{Serialize, Serializer};+use std::collections::HashMap;+use std::sync::{Arc, RwLock};++/// The main session type.+#[derive(Clone, Debug)]+pub struct Session {+    inner: Arc<RwLock<HashMap<String, String>>>,+}++impl Serialize for Session {+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>+    where+        S: Serializer,+    {+        self.inner.read().unwrap().serialize(serializer)+    }+}++impl Session {+    /// Create a new session.+    pub fn new() -> Self {+        Self {+            inner: Arc::new(RwLock::new(HashMap::new())),+        }+    }++    /// Insert a new value into the Session.+    pub fn insert(&self, k: String, v: String) -> Option<String> {+        self.inner.write().unwrap().insert(k, v)+    }++    /// Get a value from the session.+    pub fn get(&self, k: &str) -> Option<String> {+        self.inner.read().unwrap().get(k).cloned()
        self.inner.read().ok().get(k).cloned()
jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+use serde::{Serialize, Serializer};+use std::collections::HashMap;+use std::sync::{Arc, RwLock};++/// The main session type.+#[derive(Clone, Debug)]+pub struct Session {+    inner: Arc<RwLock<HashMap<String, String>>>,+}++impl Serialize for Session {+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>+    where+        S: Serializer,+    {+        self.inner.read().unwrap().serialize(serializer)+    }+}++impl Session {+    /// Create a new session.+    pub fn new() -> Self {+        Self {+            inner: Arc::new(RwLock::new(HashMap::new())),+        }+    }++    /// Insert a new value into the Session.+    pub fn insert(&self, k: String, v: String) -> Option<String> {+        self.inner.write().unwrap().insert(k, v)
        self.inner.write().ok().insert(k, v)
jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+use serde::{Serialize, Serializer};+use std::collections::HashMap;+use std::sync::{Arc, RwLock};++/// The main session type.+#[derive(Clone, Debug)]+pub struct Session {+    inner: Arc<RwLock<HashMap<String, String>>>,

Should this be i.e. Arc<RwLock<dyn SessionTrait>>?

As in, is there any reason to not allow this to be any thing that serde can serialize?

Can be for a future PR.

jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+//! In-memory session store.+use async_std::io::{Error, ErrorKind};+use async_std::sync::{Arc, RwLock};+use http_types::cookies::Cookie;+use std::collections::HashMap;++use async_trait::async_trait;+use uuid::Uuid;++use crate::{Session, SessionStore};++/// An in-memory session store.+///+/// # Security+///+/// This store *does not* generate secure sessions, and should under no+/// circumstance be used in production. It's meant only to quickly create+/// sessions.+#[derive(Debug, Clone)]+pub struct MemoryStore {+    inner: Arc<RwLock<HashMap<String, Session>>>,+}++impl MemoryStore {+    /// Create a new instance of MemoryStore.+    pub fn new() -> Self {+        Self {+            inner: Arc::new(RwLock::new(HashMap::new())),+        }+    }+}++#[async_trait]+impl SessionStore for MemoryStore {+    /// The type of error that can occur when storing and loading errors.+    type Error = std::io::Error;++    /// Get a session from the storage backend.+    async fn load_session(&self, cookie: Cookie<'_>) -> Result<Option<Session>, Self::Error> {+        let id = Uuid::parse_str(cookie.value())+            .map_err(|_| Error::new(ErrorKind::Other, "Cookie content was not a valid uuid"))?+            .to_string();++        let inner = self.inner.read().await;+        Ok(inner.get(&id).cloned())+    }++    /// Store a session on the storage backend.+    ///+    /// The data inside the session will be url-encoded so it can be stored+    /// inside a cookie.+    async fn store_session(&self, session: Session) -> Result<String, Self::Error> {+        let mut inner = self.inner.write().await;+        let id = session.get("id").unwrap().to_string();
        let id = session.get("id")?.to_string();
jbr

comment created time in 16 hours

Pull request review commenthttp-rs/async-session

get async-session working with tide

+use serde::{Serialize, Serializer};+use std::collections::HashMap;+use std::sync::{Arc, RwLock};++/// The main session type.+#[derive(Clone, Debug)]+pub struct Session {+    inner: Arc<RwLock<HashMap<String, String>>>,+}++impl Serialize for Session {+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>+    where+        S: Serializer,+    {+        self.inner.read().unwrap().serialize(serializer)
        self.inner.read()?.serialize(serializer)
jbr

comment created time in 16 hours

Pull request review commenthttp-rs/tide

tide sessions

+use tide::prelude::*;+use tide::sessions::SessionMiddleware;

This is bigger but I think we may want to reorganize middleware into tide::middleware similar to Surf.

jbr

comment created time in 16 hours

PR opened http-rs/tide

meta: fix the DCO by adding the text of DCO-1.1

The text was missing before. The DCO helps overcome some legal controversy regarding contribution authority for MIT in particular and perhaps also Apache-2.0. The Node.js Foundation (at the time) determined it was best to just stick the whole thing in the contributing document, which is what I am replicating here.

+25 -5

0 comment

1 changed file

pr created time in 16 hours

create barnchFishrock123/tide

branch : DCO-1.1

created branch time in 16 hours

issue closedhttp-rs/tide

tide::Error type should have header setting constructor or builder

Currently, Error has from_str and new. These are not enough for serializing json and more because content-type implicitly set.

closed time in 18 hours

vertexclique

issue commenthttp-rs/tide

tide::Error type should have header setting constructor or builder

#570 was merged, which changes how errors work in middleware, and should have solved this.

vertexclique

comment created time in 18 hours

issue commenthttp-rs/surf

surf::Exception does not implement std::error::Error

I believe this was effectively solved by moving to http_types::Error in https://github.com/http-rs/surf/commit/c8366fb2b9d7d59af8e9cc7a5f9d2173d459e7ec. cc @yoshuawuyts

dtolnay

comment created time in 18 hours

PR closed http-rs/surf

Convert `Exception` to `Error` cont.

Continuation of #113 to resolve #86.

In my commit I changed all instances of BoxError with Error. I also added impl From's for log::SetLoggerError and std::io::Error

+267 -134

1 comment

19 changed files

austinsheep

pr closed time in 18 hours

pull request commenthttp-rs/surf

Convert `Exception` to `Error` cont.

We moved to http_types::Error in https://github.com/http-rs/surf/commit/c8366fb2b9d7d59af8e9cc7a5f9d2173d459e7ec.

Thanks anyways!

austinsheep

comment created time in 18 hours

PR closed http-rs/surf

Switch to a concrete Error type

Please note that this is specifically a PoC to replace usage of Box<dyn std::error::Error + Send + Sync + 'static> with a concrete surf::Error type.

There are a few things yet to figure out:

  • Documentation for surf::{Result, Error}
  • Whether or not the Error variants should be exposed to the end user or if they should be hidden. I went with hiding it because it's similar to anyhow::Error.
  • When to return a surf::Error vs alternatives (like serde_json::Error) or if surf::Error should always be used
  • How errors should be displayed. Should they be wrapped or displayed as-is?

The main Error implementation is in error.rs and is also exported at the root of the crate.

This is an alternative to simply re-exporting anyhow::Error and would be another method of fixing #86.

+167 -120

4 comments

18 changed files

belak

pr closed time in 18 hours

pull request commenthttp-rs/surf

Switch to a concrete Error type

Closing since as noted above, the better change would have been a switch to http_types::Error, which was already done in April in https://github.com/http-rs/surf/commit/c8366fb2b9d7d59af8e9cc7a5f9d2173d459e7ec!

belak

comment created time in 18 hours

Pull request review commenthttp-rs/surf

Switch to a concrete Error type

+use std::result::Result as StdResult;++use thiserror::Error as ThisError;++#[allow(missing_docs)]+pub type Result<T> = StdResult<T, Error>;++#[allow(missing_docs)]+#[derive(ThisError, Debug)]+#[error(transparent)]+pub struct Error(#[from] InternalError);++macro_rules! impl_from {+    ($bound:ty) => {+        impl From<$bound> for Error {+            fn from(err: $bound) -> Error {+                InternalError::from(err).into()+            }+        }+    };+}++impl_from!(log::kv::Error);+impl_from!(serde_urlencoded::ser::Error);+impl_from!(serde_urlencoded::de::Error);+impl_from!(std::io::Error);+impl_from!(serde_json::Error);++#[derive(ThisError, Debug)]+pub(crate) enum InternalError {

Also with http_types::Error this shouldn't be necessary, because it wraps the errors and allows you to check downcasts, like so:

match surf::get(url).await {
    Ok() -> (),
    Err(error) -> {
        if let Some(&url_err) = error.downcast_ref::<UrlError>() {
            // ...
        } else if let Some(&json_err) = error.downcast_ref::<JsonError>() {
            // ...
        }
    }
}
belak

comment created time in 18 hours

Pull request review commenthttp-rs/surf

Switch to a concrete Error type

+use std::result::Result as StdResult;++use thiserror::Error as ThisError;++#[allow(missing_docs)]+pub type Result<T> = StdResult<T, Error>;++#[allow(missing_docs)]+#[derive(ThisError, Debug)]+#[error(transparent)]+pub struct Error(#[from] InternalError);

This probably doesn't need to exist. Ideally this would just using http_types::Error instead: https://docs.rs/http-types/2.3.0/http_types/struct.Error.html

(It's implemented like this: https://github.com/http-rs/http-types/blob/master/src/error.rs)

belak

comment created time in 18 hours

Pull request review commenthttp-rs/surf

Switch to a concrete Error type

+use std::result::Result as StdResult;++use thiserror::Error as ThisError;++#[allow(missing_docs)]+pub type Result<T> = StdResult<T, Error>;

This already exists from the recent-ish https://github.com/http-rs/surf/commit/ac215cbaa1f612364aff7e1bf5ec282c862f8c90

belak

comment created time in 18 hours

delete branch Fishrock123/surf

delete branch : req-res-get-inner

delete time in 18 hours

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 999398c2a349ea870c324e8ae3c75115073fe8b1

middleware: add Redirect Should work but may not be ideal. See code comments for details. Implements https://github.com/http-rs/surf/issues/18

view details

push time in 18 hours

Pull request review commenthttp-rs/surf

middleware: add Redirect

 use std::sync::Arc; pub use http_client::{Body, HttpClient, Request, Response};  pub mod logger;+pub mod redirect;

See also https://github.com/http-rs/surf/pull/198

Fishrock123

comment created time in 18 hours

PR opened http-rs/surf

Middleware: export logger directly

See https://github.com/http-rs/surf/pull/195#discussion_r453602275

semver-major

+8 -23

0 comment

3 changed files

pr created time in 18 hours

create barnchFishrock123/surf

branch : logger-middleware-export

created branch time in 18 hours

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 253b86de4c5bc88ac80d92748ca5a9c13696f8f4

fixup! improved docs, addressed comments

view details

push time in 18 hours

issue commenthttp-rs/surf

Deal with Body cloning / Allow phased sends from `HttpClient`

partial response

To be honest, I'm also not sure. I may be assuming some things about the http spec that aren't true. I am not sure that this is good idea, but a client could, for example, send part of the request, wait a bit to see if the server immediately responds with a 3XX, and if not, then send the body.

curl will make the first POST request as a POST. If it's a redirect, it does the -following- one as a GET to see if it's another redirect, and then does a final POST on the final location. idk if that helps a lot, though.

Any idea why it does this? Why not just POST?

I wonder how curl handles it's body/stream...

Fishrock123

comment created time in a day

pull request commenthttp-rs/surf

Switch to a concrete Error type

At a glance this sounds right to me, that’s what Tide does.

belak

comment created time in a day

issue commenthttp-rs/surf

Deal with Body cloning / Allow phased sends from `HttpClient`

Another possible option for retires is to have that be behind a compiler flag that requires all body streams to be Clone... but honestly I'm not 100% sure if or how that would be possible for the streams to implement? Not sure.

Fishrock123

comment created time in 2 days

pull request commenthttp-rs/tide

src: move State off of Request (WIP)

Err... this isn't solving the issue that #642 and #644 solve... this is just general ergonomics, imo? Likewise see https://github.com/http-rs/tide/issues/643#issuecomment-657621351

Fishrock123

comment created time in 2 days

issue commenthttp-rs/tide

Consider moving `State` off of `Request`

Just to be clear, this isn't to solve the issue that #644/#642 solves... to me this is just general ergonomics cleanup that was encountered during those. It seems like there would be a lot less for users to type when they don't need state and also less for middleware which will probably never interact with a specific state type. Related, this is probably a compilation type boost, since there will be less generic functions to worry about.

Fishrock123

comment created time in 2 days

PR closed http-rs/tide

Server: add with_shared_state()

Allows true state sharing for multiple tide server applications without Arc<Arc<State>>.

See discord discussion: https://discordapp.com/channels/598880689856970762/649056551835009097/731205374832541746

+88 -5

8 comments

2 changed files

Fishrock123

pr closed time in 2 days

pull request commenthttp-rs/tide

Server: add with_shared_state()

Closing in favor of https://github.com/http-rs/tide/pull/644

Fishrock123

comment created time in 2 days

issue commenthttp-rs/surf

Deal with Body cloning / Allow phased sends from `HttpClient`

I don't know if there is a proper term, but:

Send headers, await a partial response.

It would be nice to not have to send the body if we don;'t have to, essentially.

Fishrock123

comment created time in 2 days

issue commenthttp-rs/tide

Consider moving `State` off of `Request`

https://github.com/http-rs/tide/pull/645 has an impl conflict for some reason but is effectively what I'm proposing here.

Fishrock123

comment created time in 3 days

PR opened http-rs/tide

src: move State off of Request (WIP)
error[E0119]: conflicting implementations of trait `endpoint::Endpoint<_>`:
  --> src\endpoint.rs:70:1
   |
54 | / impl<State, F, Fut, Res> Endpoint<State> for F
55 | | where
56 | |     State: Send + Sync + 'static,
57 | |     F: Send + Sync + 'static + Fn(Request) -> Fut,
...  |
67 | |     }
68 | | }
   | |_- first implementation here
69 |
70 | / impl<State, F, Fut, Res> Endpoint<State> for F
71 | | where
72 | |     State: Send + Sync + 'static,
73 | |     F: Send + Sync + 'static + Fn(Request, State) -> Fut,
...  |
83 | |     }
84 | | }
   | |_^ conflicting implementation

Not sure I understand this error. F should be a distinct type for both??

+117 -58

0 comment

14 changed files

pr created time in 3 days

issue commenthttp-rs/tide

Consider moving `State` off of `Request`

@Silentdoer Could you elaborate more?

Fishrock123

comment created time in 3 days

create barnchFishrock123/tide

branch : request-without-state

created branch time in 3 days

pull request commenthttp-rs/tide

Server: require State to be Clone

I was on the edge about it, but i should have said in my OP: "Is non-Arc Clone" actually what a user would expect?"

I'm not sure it is personally? Like, your state will not actually be shared between anything at all if it's not an Arc - it will only contain the data set originally and set within any specific request. That isn't "shared" state in any sense. If this is really for shared state I'm not honestly sure this is the correct direction...

Fishrock123

comment created time in 3 days

push eventFishrock123/tide

Jeremiah Senkpiel

commit sha da703eb25193b0e0016d0aa3b72712f87e8bf33b

Server: require State to be Clone Alternative to https://github.com/http-rs/tide/pull/642 This approach is more flexible but requires the user ensure that their state implements/derives `Clone`, or is wrapped in an `Arc`. Co-authored-by: Jacob Rothstein <hi@jbr.me>

view details

push time in 3 days

PR opened http-rs/tide

Server: require State to be Clone

Alternative to https://github.com/http-rs/tide/pull/642

This approach is more flexible but requires the user ensure that their state implements/derives Clone, or is wrapped in an Arc.

Co-authored-by: Jacob Rothstein hi@jbr.me

Notably while this has less new API surface, this requires more from user code.

+57 -51

0 comment

10 changed files

pr created time in 3 days

push eventFishrock123/tide

Jeremiah Senkpiel

commit sha ab7e54d15f7c224590d4d3f9727365272b983801

Server: require State to be Clone Alternative to https://github.com/http-rs/tide/pull/642 This approach is more flexible but requires the user ensure that their state implements/derives `Clone`, or is wrapped in an `Arc`. Co-authored-by: Jacob Rothstein <hi@jbr.me>

view details

push time in 3 days

pull request commenthttp-rs/tide

Server: add with_shared_state()

So @jbr got the above to compile using pin-project-lite: https://gist.github.com/jbr/b0fd2964eb57a1d8d512e4d167ad6554

However I think that Request probably shouldn't hold the State. See https://github.com/http-rs/tide/issues/643

Fishrock123

comment created time in 3 days

issue openedhttp-rs/tide

Move `State` off of `Request`

It would be nice to not have Request have a generic parameter, for e.g. the AsyncRead trait which requires pinning. See https://github.com/http-rs/tide/pull/642#issuecomment-657141853 for where this was originally encountered.

However in interest of keeping middleware simple it would still be nice to allow (Request, Next) -> Fut<Result<>>, but for State it would probably ideal to have an extra parameter, kinda like Surf's Client, e.g. (Request, State, Next) -> Fut<Result<>>.

I was thinking maybe server.middleware() / endpoints could take impl Into<Middleware<State>> / endpoint, and so then that trait could be applied to both of the above with an extra function wrapper for the simple case, allowing both to work, and scoping State to the middleware/endpoint stack.

created time in 3 days

startedron-rs/ron

started time in 3 days

starteddtolnay/cargo-expand

started time in 4 days

push eventFishrock123/tide

Jeremiah Senkpiel

commit sha 2733a824416de2cd6ff98cb49d5958b6a6372a59

Server: require State to be Clone (NOT WORKING) `impl<State> Read for Request<State>` requires `DerefMut` ...

view details

push time in 4 days

create barnchFishrock123/tide

branch : server-state-clone

created branch time in 4 days

pull request commenthttp-rs/tide

Server: add with_shared_state()

Uhhh, I'm not sure that is possible. impl<State> Read for Request<State> requires DerefMut...

Fishrock123

comment created time in 4 days

issue commenthttp-rs/tide

tide::Response::set_content_type usage

Should be fixed whenever we pull in an http-types 2.4.0...

zakarumych

comment created time in 4 days

delete branch Fishrock123/http-types

delete branch : mime-from-str

delete time in 4 days

push eventhttp-rs/http-types

Jeremiah Senkpiel

commit sha 68c1866576bc21b37a61e6ffe8029c15d3943205

Mime: add From<&str> Refs: https://github.com/http-rs/tide/issues/575

view details

Jeremiah Senkpiel

commit sha 1716bc9c683389dc94a368901056273ffb2d7e00

Merge pull request #179 from Fishrock123/mime-from-str Mime: add From<&str>

view details

push time in 4 days

PR merged http-rs/http-types

Mime: add From<&str>

Refs: https://github.com/http-rs/tide/issues/575

+6 -0

1 comment

1 changed file

Fishrock123

pr closed time in 4 days

pull request commenthttp-rs/tide

Server: add with_shared_state()

I think that was part of the stated issue though, that it's annoying to have to deal with an Arc<> in the middleware when it's probably going to be anyways?

Fishrock123

comment created time in 4 days

pull request commenthttp-rs/tide

Server: add with_shared_state()

Yeah, the idea is to be able to have more than one server share the same state without passing an Arc, which would become Arc<Arc<>> and then passed to middleware as an Arc<State>.

I think this was the intention to begin with but probably was mistaken?

Does State: Clone prevent us from having an Arc internally that is different from a user-passed Arc?

Fishrock123

comment created time in 4 days

pull request commenthttp-rs/tide

use async_trait to simplify async signatures

async-trait's code is pretty complex... does it still actually create a pinned boxed future from these async functions, or just a future directly?

jbr

comment created time in 4 days

starteddtolnay/async-trait

started time in 4 days

PR opened http-rs/tide

Server: add with_shared_state()

Allows true state sharing for multiple tide server applications without Arc<Arc<State>>.

See discord discussion: https://discordapp.com/channels/598880689856970762/649056551835009097/731205374832541746

+88 -5

0 comment

2 changed files

pr created time in 4 days

create barnchFishrock123/tide

branch : server-shared-state

created branch time in 4 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 4a3941bd357b5ed38a15303d70844f966e60d5c7

Request, Response: inner types as_ref/mut Allows access to the underlying Request or Response by reference, including mutably. Mirrors Tide's api for this. This (mutable reference) will be necessary in order to have https://github.com/http-rs/surf/pull/195 on top of https://github.com/http-rs/surf/pull/194 without adding another specialized public api for adjusting the url.

view details

push time in 5 days

PR opened http-rs/surf

Request, Response: inner types ref&mut

Allows access to the underlying Request or Response by reference, including mutably.

This will be necessary to have https://github.com/http-rs/surf/pull/195 on top of https://github.com/http-rs/surf/pull/194 without adding another specialized public api for adjusting the url.

+17 -1

0 comment

2 changed files

pr created time in 5 days

create barnchFishrock123/surf

branch : req-res-get-inner

created branch time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha cb7fa8860464085e3be27f0a8fa3dcfaa98710ee

middleware: add Redirect Should work but isn't ideal. See code comments for details. Implements https://github.com/http-rs/surf/issues/18

view details

push time in 5 days

push eventFishrock123/tide-compress

Jeremiah Senkpiel

commit sha c8a35146921b3fc18b6d0ff8fce4800563559f1e

deps: tide @ 0.11

view details

push time in 5 days

issue openedhttp-rs/surf

Deal with Body cloning / Allow phased sends from `HttpClient`

As described in https://github.com/http-rs/surf/pull/195 (Redirects), but more severely in order to address https://github.com/http-rs/surf/issues/169 (Retries) some form of either body cloning and/or phased client sending is necessary.

The easier case is probably phased sending, required for Redirects. Phased sending would partially solve the issue for Retries, but only partially, although enough to implement a sort-of working Retry middleware.

The problem here is that in some cases we don't want the Body stream to be consumed, or at least not right when we send the request headers.

Ideal for Redirects:

  • Send headers, await a partial response. If it's 3XX don't bother sending the body and go through the redirect first.
    • (I hope I understand http enough that the above is actually possible. If not, it is the same as Retry.)

Ideal for Retries:

  • Body stream can be duplicated (Cloned), i.e. in the case of a file, a new FD to the same file, through the same transforms.
  • Ideally it would be duplicate-able after the request is sent and fails, so that we don't have to allocate up front, but maybe that's just the price to pay for Retries.
  • This is needed so that we can make a second identical request including body from an http_types::Request.

created time in 5 days

pull request commenthttp-rs/surf

src: overhaul Client, rework Request and Middleware, add builder

I have made a possible additional patch at https://github.com/Fishrock123/surf/pull/1 that re-adds surf::{method}().middleware() in the form of RequestBuilder::middleware(), and an Option<Vec<Arc<dyn Middleware>>> on RequestBuilder.

Fishrock123

comment created time in 5 days

PR opened Fishrock123/surf

RequestBuilder: add `.middleware()`

A possible addition to https://github.com/http-rs/surf/pull/194, which would be less breaking and possibly more ergonomic, and possibly light enough to warrant doing.

+58 -10

0 comment

4 changed files

pr created time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 21f8be5efb0b8ed50c4e745c2b7980e889936001

RequestBuilder: add `.middleware()` A possible addition to https://github.com/http-rs/surf/pull/194, which would be less breaking and possibly more ergonomic, and possibly light enough to warrant doing.

view details

push time in 5 days

create barnchFishrock123/surf

branch : request-builder-with-middleware

created branch time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha e4e7a231511348d9340f83a5657fe7d9041ae4dc

middleware: add Redirect Should work but isn't ideal. See code comments for details. Implements https://github.com/http-rs/surf/issues/18

view details

push time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 2c2507360e73604be5a9f6e0865a51e6c35bd5fc

fixup! fix next_reuse example

view details

push time in 5 days

issue commenthttp-rs/surf

Pass `surf::Request` and `surf::Response` through middleware

PR at https://github.com/http-rs/surf/pull/194

yoshuawuyts

comment created time in 5 days

PR opened http-rs/surf

middleware: add Redirect

Should work but isn't ideal. See code comments for details.

Implements https://github.com/http-rs/surf/issues/18

+119 -0

0 comment

3 changed files

pr created time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha d6abfa12d4b01de620a5540ce52b321813a6b3fa

middleware: add Redirect Should work but isn't ideal. See code comments for details. Implements https://github.com/http-rs/surf/issues/18

view details

push time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha f7aef9309886132a006cfa7392a91561e93125f1

fixup! fmt

view details

push time in 5 days

create barnchFishrock123/surf

branch : redirect-middleware

created branch time in 5 days

Pull request review commenthttp-rs/tide

extensible entrypoint for app.listen

 kv-log-macro = "1.0.4" serde = "1.0.102" serde_json = "1.0.41" route-recognizer = "0.2.0"+futures = "0.3.5"

Fwiw futures-util has FuturesUnordered.

jbr

comment created time in 5 days

pull request commenthttp-rs/tide

introduce an extension trait for testing servers

still lgtm

jbr

comment created time in 5 days

Pull request review commenthttp-rs/tide

Don't panic on missing path param

 impl<State> Request<State> {     ///     /// # Errors     ///-    /// Yields an `Err` if the parameter was found but failed to parse as an+    /// Yields a `ParamError::ParsingError` if the parameter was found but failed to parse as an     /// instance of type `T`.     ///-    /// # Panics+    /// Yields a `ParamError::NotFound` if `key` is not a parameter for the route.     ///-    /// Panic if `key` is not a parameter for the route.-    pub fn param<T: FromStr>(&self, key: &str) -> Result<T, T::Err> {+    /// # Examples+    ///+    /// ```no_run+    /// # use async_std::task::block_on;+    /// # fn main() -> Result<(), std::io::Error> { block_on(async {+    /// #+    /// use tide::{Request, Result};+    ///+    /// async fn greet(req: Request<()>) -> Result<String> {+    ///     let name = req.param("name").unwrap_or("world".to_owned());+    ///     Ok(format!("Hello, {}!", name))+    /// }+    ///+    /// let mut app = tide::new();+    /// app.at("/hello").get(greet);+    /// app.at("/hello/:name").get(greet);+    /// app.listen("127.0.0.1:8080").await?;+    /// #+    /// # Ok(()) })}+    /// ```+    pub fn param<T: FromStr>(&self, key: &str) -> Result<T, ParamError<T::Err>> {

Isn't this the same as saying Result<Option<T>, T::Err>?

vladan

comment created time in 5 days

issue commenthttp-rs/tide

Why is Server::middleware an Arc<Vec<Arc<>>>?

I ended up changing Surf's to also be Arc<Vec<Arc<>>> in https://github.com/http-rs/surf/pull/194/files#diff-31bbf71c54bca98a0ae3d40a327af940R32 ... I know the Arc<Vec<>> part was necessary but I'm not sure about the inner Arcs.

Fishrock123

comment created time in 5 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 6250b119386d56470297ce6ee520d88ed6f40f52

fixup! Request::builder

view details

Jeremiah Senkpiel

commit sha 19ccfce13cad3935121d9a209d3064cc8132ba10

fixup! fixed all outstanding doctest failures

view details

Jeremiah Senkpiel

commit sha 90285e1bd37bdec5ca5f64e2ec47c6ae4348020d

fixup! re-enable disabled lib attributes

view details

push time in 5 days

release http-rs/http-client

4.0.0

released time in 6 days

push eventFishrock123/surf

Jeremiah Senkpiel

commit sha 883f59d15c3b06d7d4f743fd5cf326b7c5e8285f

fixup! cargo fmt

view details

Jeremiah Senkpiel

commit sha 16fa7f240b703d6c6c7e9e24126bac711916f5d6

fixup! fix stack overflow oops, this called `Client::send` recursively, rather than `HttpClient::send`...

view details

push time in 6 days

PR opened http-rs/surf

Reviewers
src: overhaul Client, rework Request and Middleware, add builder

A practical implementation of https://github.com/http-rs/surf/issues/192

Please see that issue for full background on this PR.

This includes the following changes:

  • surf::{method}() now returns RequestBuilder.
  • Adds RequestBuilder.
  • Changes Middleware to roughly (surf::Request, surf::Client, surf::Next) -> Result<surf::Response>.
  • Changes Endpoint to roughly (surf::Request, surf::Client) -> Result<surf::Response>
  • Adds Client::send(impl Into<Request>)
  • Adds Client::middleware()
  • Adds surf::client()
  • Removes Request::middleware() (moved to Client)
  • Removed impl Future for Request & related (moved to RequestBuilder or Client::send())
  • Removes Client::{method}() (no longer makes much sense)
  • (and more lesser changes)

This is absolutely semver-major.

Note: This presently causes stack overflows on the tests. I'm not sure why but I suspect it has to do with the middleware changes.

+467 -582

0 comment

13 changed files

pr created time in 6 days

push eventFishrock123/surf

Sven Lechner

commit sha 79e49f0c70046046ec84c46d936efda5acff083d

feat\!: implement From instead of TryFrom for Request This commit replaces the current TryFrom implementation with a From implementation to convert http_types::Request objects into surf::Request objects. The old implementation had no errors that could have been produced, making the TryFrom successful 100% of the times.

view details

Sven Lechner

commit sha 3af1976f07320faaa895c76df9e89fef6c3e9cd3

fix clippy and fmt

view details

Jeremiah Senkpiel

commit sha e6cd23052c9d05133a07814c73c2f05b4b0c7f5d

Response: change internal field to "res" More similar to tide, makes keeping api in sync easier.

view details

Jeremiah Senkpiel

commit sha c22693e2e0a42e0d975fbc3c508b86c677256779

Request, Response: update method parity with Tide Adds many methods on http_types request/response that Tide exposes. Supercedes the following PRs: - https://github.com/http-rs/surf/pull/182 - https://github.com/http-rs/surf/pull/174 - https://github.com/http-rs/surf/pull/171

view details

Jeremiah Senkpiel

commit sha 0c73af710e7f65f13c60c07ccfdbfb8b7a27960b

src: use http_types::mime instead of mime crate This is a breaking change, reflects tide's apis.

view details

Jeremiah Senkpiel

commit sha ac215cbaa1f612364aff7e1bf5ec282c862f8c90

src, lib: expose http_types as surf::http This also adds `surf::Result` and changes apis to return it instead of `http_types::Result`. Refs: https://github.com/http-rs/surf/pull/191#discussion_r447476865

view details

Sven

commit sha 712bd61153dc979392060c734c8386d71daa9398

Merge branch 'master' into try_from_to_from

view details

Sven

commit sha 1ab963d83eb4953090433ba21c1d630f6199747e

fix for master merge

view details

Sven

commit sha 665f97b91e17cf67723e05bb28530a3b09f51cb2

fix merge again I think I accepted the wrong changes :(

view details

Yoshua Wuyts

commit sha 6654ed85184a580801f61b6f39741a7e44016741

Merge pull request #190 from SirWindfield/try_from_to_from TryFrom to From for surf::Request

view details

Lyle Mantooth

commit sha 917fb6972ba31202dc5132013724488415aa7d4c

WIP: use dynamic dispatch for HttpClient.

view details

Robin Appelman

commit sha cf70468f24593d91dd494a2ad9e0a9bf0e339ea6

remove debug+clone trait bounds on HttpClient and use Arc to allow cloning HttpClient trait object

view details

Jeremiah Senkpiel

commit sha 8c686d2ab69dbf405d918825b440941038050d1f

src: fix http_client cfg conditionals Prefer `H1Client` if `--features=h1-client` is set. Fixes the compilation of the two previous commits.

view details

Jeremiah Senkpiel

commit sha bf4bf8da441fd6d072acdbf398ef8b5dea5e558f

Merge pull request #193 from Fishrock123/dyn-HttpClient dyn HttpClient

view details

Jeremiah Senkpiel

commit sha 5a84c802d76045f8114fd54550799c2d36ed4369

src: overhaul Client, rework Request and Middleware, add builder A practical implementation of https://github.com/http-rs/surf/issues/192

view details

push time in 6 days

push eventFishrock123/surf

Sven Lechner

commit sha 79e49f0c70046046ec84c46d936efda5acff083d

feat\!: implement From instead of TryFrom for Request This commit replaces the current TryFrom implementation with a From implementation to convert http_types::Request objects into surf::Request objects. The old implementation had no errors that could have been produced, making the TryFrom successful 100% of the times.

view details

Sven Lechner

commit sha 3af1976f07320faaa895c76df9e89fef6c3e9cd3

fix clippy and fmt

view details

Jeremiah Senkpiel

commit sha e6cd23052c9d05133a07814c73c2f05b4b0c7f5d

Response: change internal field to "res" More similar to tide, makes keeping api in sync easier.

view details

Jeremiah Senkpiel

commit sha c22693e2e0a42e0d975fbc3c508b86c677256779

Request, Response: update method parity with Tide Adds many methods on http_types request/response that Tide exposes. Supercedes the following PRs: - https://github.com/http-rs/surf/pull/182 - https://github.com/http-rs/surf/pull/174 - https://github.com/http-rs/surf/pull/171

view details

Jeremiah Senkpiel

commit sha 0c73af710e7f65f13c60c07ccfdbfb8b7a27960b

src: use http_types::mime instead of mime crate This is a breaking change, reflects tide's apis.

view details

Jeremiah Senkpiel

commit sha ac215cbaa1f612364aff7e1bf5ec282c862f8c90

src, lib: expose http_types as surf::http This also adds `surf::Result` and changes apis to return it instead of `http_types::Result`. Refs: https://github.com/http-rs/surf/pull/191#discussion_r447476865

view details

Sven

commit sha 712bd61153dc979392060c734c8386d71daa9398

Merge branch 'master' into try_from_to_from

view details

Sven

commit sha 1ab963d83eb4953090433ba21c1d630f6199747e

fix for master merge

view details

Sven

commit sha 665f97b91e17cf67723e05bb28530a3b09f51cb2

fix merge again I think I accepted the wrong changes :(

view details

Yoshua Wuyts

commit sha 6654ed85184a580801f61b6f39741a7e44016741

Merge pull request #190 from SirWindfield/try_from_to_from TryFrom to From for surf::Request

view details

Lyle Mantooth

commit sha 917fb6972ba31202dc5132013724488415aa7d4c

WIP: use dynamic dispatch for HttpClient.

view details

Robin Appelman

commit sha cf70468f24593d91dd494a2ad9e0a9bf0e339ea6

remove debug+clone trait bounds on HttpClient and use Arc to allow cloning HttpClient trait object

view details

Jeremiah Senkpiel

commit sha 8c686d2ab69dbf405d918825b440941038050d1f

src: fix http_client cfg conditionals Prefer `H1Client` if `--features=h1-client` is set. Fixes the compilation of the two previous commits.

view details

Jeremiah Senkpiel

commit sha bf4bf8da441fd6d072acdbf398ef8b5dea5e558f

Merge pull request #193 from Fishrock123/dyn-HttpClient dyn HttpClient

view details

push time in 6 days

issue closedhttp-rs/surf

Making the `Client` to use dynamic dispatch

Instead of passing the internal implementation in Client<T: HttpClient>, why not just hiding it by using dynamic dispatch and a smart pointer? In the end, the performance hit would not be that bad compared to the time taken by the network traffic itself.

So, instead of

#[derive(Debug, Default)]
pub struct Client<C: HttpClient> {
    client: C,
}

we'd have

#[derive(Debug, Default)]
pub struct Client {
    client: Box<dyn HttpClient>,
}

Would be nice in some of our cases, where we need to keep the Client in a struct, and we might need to switch the underlying implementation e.g. in cases where we build for wasm. Having dynamic dispatch wouldn't change all the type signatures.

closed time in 6 days

pimeys

issue commenthttp-rs/surf

Making the `Client` to use dynamic dispatch

Done in https://github.com/http-rs/surf/pull/193

pimeys

comment created time in 6 days

push eventhttp-rs/surf

Lyle Mantooth

commit sha 917fb6972ba31202dc5132013724488415aa7d4c

WIP: use dynamic dispatch for HttpClient.

view details

Robin Appelman

commit sha cf70468f24593d91dd494a2ad9e0a9bf0e339ea6

remove debug+clone trait bounds on HttpClient and use Arc to allow cloning HttpClient trait object

view details

Jeremiah Senkpiel

commit sha 8c686d2ab69dbf405d918825b440941038050d1f

src: fix http_client cfg conditionals Prefer `H1Client` if `--features=h1-client` is set. Fixes the compilation of the two previous commits.

view details

Jeremiah Senkpiel

commit sha bf4bf8da441fd6d072acdbf398ef8b5dea5e558f

Merge pull request #193 from Fishrock123/dyn-HttpClient dyn HttpClient

view details

push time in 6 days

PR merged http-rs/surf

dyn HttpClient

This is a rebase of @islandusurper and @icewind1991's commits as linked in https://github.com/http-rs/surf/issues/69, based on an http-client branch which actually fixes the Sized and Error bounds issues on the HttpClient trait.

This makes Client no longer a generic, simplifying things as noted in https://github.com/http-rs/surf/issues/192 and also allowing things such as https://github.com/http-rs/surf/issues/150 (static client), while also fixing other reported issues.

Todo:

  • [x] Merge https://github.com/http-rs/http-client/pull/31
  • [x] Merge https://github.com/http-rs/http-client/pull/30
  • [x] Merge https://github.com/http-rs/http-client/pull/29
  • [x] http-client release
  • [x] rebase/squash (remove git dep + always compiling commits(?))
+131 -127

0 comment

9 changed files

Fishrock123

pr closed time in 6 days

push eventFishrock123/surf

Lyle Mantooth

commit sha 917fb6972ba31202dc5132013724488415aa7d4c

WIP: use dynamic dispatch for HttpClient.

view details

Robin Appelman

commit sha cf70468f24593d91dd494a2ad9e0a9bf0e339ea6

remove debug+clone trait bounds on HttpClient and use Arc to allow cloning HttpClient trait object

view details

Jeremiah Senkpiel

commit sha 8c686d2ab69dbf405d918825b440941038050d1f

src: fix http_client cfg conditionals Prefer `H1Client` if `--features=h1-client` is set. Fixes the compilation of the two previous commits.

view details

push time in 6 days

created tagFishrock123/http-client

tag4.0.0

Types and traits for http clients

created time in 6 days

created taghttp-rs/http-client

tag4.0.0

Types and traits for http clients

created time in 6 days

push eventFishrock123/http-client

Jeremiah Senkpiel

commit sha 1ba06780f667a76a1e0c12a5725e40c8bd4d17fc

HttpClient: remove Error type bounds This makes using HttpClient as a dynamic Trait object, such as in https://github.com/http-rs/surf/issues/69 substantially more complex. This complexity can be reduced by having the backing client implementor handle the error translation (which was already required to begin with).

view details

Jeremiah Senkpiel

commit sha 19ee099ff32184c55617232ddfd9059485c1fdf9

Merge pull request #29 from Fishrock123/remove-error-type-bounds HttpClient: remove Error type bounds

view details

Jeremiah Senkpiel

commit sha f50f436786397318d681b9e309e0a23384e6f240

4.0.0 This release allows `HttpClient` to be used as a dynamic Trait object. - `HttpClient`: removed `Clone` bounds. - `HttpClient`: removed `Error` type.

view details

push time in 6 days

push eventhttp-rs/http-client

Jeremiah Senkpiel

commit sha f50f436786397318d681b9e309e0a23384e6f240

4.0.0 This release allows `HttpClient` to be used as a dynamic Trait object. - `HttpClient`: removed `Clone` bounds. - `HttpClient`: removed `Error` type.

view details

push time in 6 days

push eventFishrock123/http-client

Jeremiah Senkpiel

commit sha 4da36577b0d4cfe766458fb93e30415695af3573

CI: run fmt & docs on nightly for #[feature]

view details

Yoshua Wuyts

commit sha 46e9b843084af2a0da8db85e4c7c5d5835d5856d

Merge pull request #31 from Fishrock123/fix-ci CI: run fmt & docs on nightly for #[feature]

view details

Jeremiah Senkpiel

commit sha 7d9e9c572d0cdedacd5fd068380b5a19c2bd7a44

HttpClient: remove Clone bounds, ensure unsized This allows `HttpClient` to be used as a dynamic Trait Object, which requires that the trait not have the `Sized` bounds, which was implied by `Clone`. Users should wrap `HttpClient` in an `Rc`/`Arc` if Cloning/Sharing is necessary.

view details

Jeremiah Senkpiel

commit sha 44a32b46584c387e440ad1c3a181e3ee95b82fae

Merge pull request #30 from Fishrock123/allow-dyn-HttpClient HttpClient: remove Clone bounds, ensure unsized

view details

Jeremiah Senkpiel

commit sha bf4e8a7d774280db9a164392a1b79c5db86e767c

4.0.0 This release allows `HttpClient` to be used as a dynamic Trait object. - `HttpClient`: removed `Clone` bounds. - `HttpClient`: removed `Error` type.

view details

push time in 6 days

PR closed http-rs/http-client

Make HTTPClient object safe
  • Adds the Sized bound to HTTPClient
  • Removes the Error associated type and makes it dynamically dispatched. This allows objects of the type dyn HTTPClient instead of dyn HTTPClient<ErrorType>
  • Makes both clients confirm with then new trait
+11 -17

5 comments

3 changed files

skade

pr closed time in 6 days

pull request commenthttp-rs/http-client

Make HTTPClient object safe

Superseded by the merged https://github.com/http-rs/http-client/pull/29, thanks anyway!

skade

comment created time in 6 days

more