http4s icon indicating copy to clipboard operation
http4s copied to clipboard

History Client Middleware

Open ChristopherDavenport opened this issue 2 years ago • 9 comments

Browsers Keep a history of calls made by the browser. Would be nice if we had a client middleware which did similar in case we ever want to show and capture the interactions that a specific flow may have generated without leaking confidential information like headers/cookies/etc.

// Browser save Title HTML and Favicon - Maybe a later pass maybe just options that are none for now to keep bincompat
// Maybe we want a builder class for this so we can add additional information to it.

def middleware[F[_]: MonadCancelThrow](client: Client[F], history: Ref[F, List[(HttpDate, Method, Uri)], maxSize: Int): Client[F] = Client[F]{(req: Request[F]) =>
  Resource.eval(req.headers.get[Date].fold(HttpDate.now[F])(d => d.date.pure[F]).flatMap{ date => 
     val allTheOtherStuff 
     history.modify(l => event :: l) >>
     dropElementsAfterN >>
     clinet.run(req)
  }
} // obviously psuedo

ChristopherDavenport avatar Jul 08 '22 15:07 ChristopherDavenport

I'll take a look!

SallyPerez avatar Jul 08 '22 15:07 SallyPerez

@ChristopherDavenport do I need special permission to push up my branch? I was trying to push up my wip branch but got the following error:

ERROR: Permission to http4s/http4s.git denied to SallyPerez.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SallyPerez avatar Jul 12 '22 19:07 SallyPerez

@SallyPerez Thanks for your work on this! Indeed, you cannot push a branch to this repository. But you can create your own fork, push there, and start a pull request :)

https://docs.github.com/en/get-started/quickstart/contributing-to-projects

Let us know if you have any questions!!

armanbilge avatar Jul 12 '22 19:07 armanbilge

@armanbilge apologies for not updating here, I've have been working on this and am almost done, working on adding a test for it before submitting a PR

SallyPerez avatar Feb 02 '23 16:02 SallyPerez

@gringrape Thanks for volunteering, and for your work on the client docs. There are still plenty more issues, and we'd still love to have the help elsewhere!

rossabaker avatar Feb 02 '23 16:02 rossabaker

@gringrape Thanks for volunteering, and for your work on the client docs. There are still plenty more issues, and we'd still love to have the help elsewhere!

Thank you! Actually, I'd love to contribute more. I'll check issues. :)

gringrape avatar Feb 03 '23 01:02 gringrape

@rossabaker is this something that you are still wanted to achieve? I would like to help because it is something that on my daily use case it is interesting. @SallyPerez If you are interested into I can help you on this.

albertoadami avatar Oct 07 '23 15:10 albertoadami

Thanks for the offers of help, but it's in active progress.

rossabaker avatar Jan 01 '24 01:01 rossabaker

It's in progress. Thanks for the offer @albertoadami

SallyPerez avatar Jan 03 '24 16:01 SallyPerez