Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 08 14:35

    msrd0 on master

    Send the State to the session b… (compare)

  • May 08 14:35
    msrd0 closed #468
  • May 08 14:34
    msrd0 milestoned #467
  • May 08 14:32
    msrd0 labeled #467
  • May 08 14:32
    msrd0 commented #467
  • May 08 14:28
    msrd0 auto_merge_enabled #468
  • May 08 14:22
    msrd0 milestoned #468
  • May 08 14:22
    msrd0 unlabeled #468
  • May 08 14:21
    codecov[bot] commented #468
  • May 08 14:21
    msrd0 synchronize #468
  • May 06 22:06
    StephenWakely commented #468
  • May 02 09:05
    rp- commented #542
  • May 02 00:05
    msrd0 labeled #542
  • May 02 00:05
    msrd0 commented #542
  • May 01 20:40
    rp- opened #542
  • Apr 29 16:18

    dependabot[bot] on cargo

    (compare)

  • Apr 29 16:18

    msrd0 on master

    Update time requirement from 0.… (compare)

  • Apr 29 16:18
    msrd0 closed #541
  • Apr 29 16:09
    msrd0 auto_merge_enabled #541
  • Apr 29 16:07
    msrd0 synchronize #541
Denis Lisov
@tanriol
Note that in the current state of Rust async trait adds a level of Boxing, AFAIK.
Judson Lester
@nyarly
Isn't that every async though?
Or is async just Pin<Future<T>>?
Dominic
@msrd0:msrd0.de
[m]
no that's just a limitation of traits where you cannot return impl Future
afaik async fn foo() -> Result translates to fn foo() -> impl Future<Output = Result> with no boxing involved, and the concrete type being inferred by the compiler (and which is also some autogenerated private type)
Stefan Schindler
@dns2utf8
@msrd0:msrd0.de and all:
Sorry for the late reply. What I want is the webserver responding to a post request by making another get request
So my scenario is this:
Client --{POST}--> GothamServer --{GET}--> some other server with the information I need to answer the client
Dominic
@msrd0:msrd0.de
[m]
yes that's certainly possible. gotham would be the part that communicates with the client, and then you'd use a client library like reqwest or surf to make your get request inside the handler
Rodrigo Batista
@rodrigodevelms
Hi folks. Gothan ready to build a ERP system?
Alex Hansen
@sezna
Sure. It's a capable web framework. I suspect for an ERP system, you'll be spending more of your time in database and UI code than in your web server code.
Jan Mazur
@mzr
Hi. I have an already established connection (AsyncRead + AsyncWrite). Based on some initial data received I would like to either proceed with a custom logic or plug it into gotham to handle http. Is that possible with gotham? Could you point me into right direction how to do that?
tanriol
@tanriol:matrix.org
[m]
@mzr: Probably not out of the box. I'd suggest looking at bind_server (source) to see (a) if it would be enough, (b) how it's dont internally.
Chris Emerson
@jugglerchris
Hi. Is there a convenient way to run tests with an sqlite in-memory database? I could pass ":memory:" to Repo::new(), but it's not obvious how to run the diesel migrations.
Marwan Rabbâa
@waghanza
Hi,
Their is something I don't understand in Cargo.lock, should not in fix / expose feature from hyper ? I have no rust skill but hyper is in 0.14 so we need to fix version in Cargo.toml
the-benchmarker/web-frameworks#3690
Dominic
@msrd0:msrd0.de
[m]
@waghanza: gotham re-exports the hyper crate, so I strongly advise you use gotham::hyper and don't depend on your own version of hyper
@jugglerchris: I don't think the diesel middleware currently supports this, so for now your best bet is probably to create a temporary file and use that as the database. Feel free to open an issue/PR to improve this
Marwan Rabbâa
@waghanza
@msrd0:msrd0.de May I ask yo to review above PR, please
Chris Emerson
@jugglerchris
@msrd0:msrd0.de Thanks - a temporary file is fine but slightly unsatisfying - but no biggie.
Chris Emerson
@jugglerchris
Next question... what do people use for the session middleware backend? I guess it's probably not much effort wrapping a gotham_middleware_diesel table, but I guess I'd expect someone to have done so already. :-) (In the absence of a pre-existing one the MemoryBackendwill realistically be fine for my one-off application for a child's distributed birthday party)
Dominic
@msrd0:msrd0.de
[m]
it looks like travis currently refuses to run on our repository - does anyone know why that is?
Sean Pianka
@seanpianka
Hello, should I be using hyper included in my cargo.toml, or the re-exported hyper from gotham?
Dominic
@msrd0:msrd0.de
[m]
@seanpianka: I don't think you need to include hyper in your Cargo.toml file if you use gotham
Michael House
@mjhouse
Hey, does gotham have any support for error handlers? (404,500 etc.)
Dominic
@msrd0:msrd0.de
[m]
@mjhouse: that depends... for a 404 returned by the router because there was no matching path, there's no convenient way to catch that error unfortunately. For other errors like 500, assuming they're not caused by a panic, you could use a middleware that checks the returned response from the handler and creates a new response if it was a server error
Michael House
@mjhouse
@msrd0:msrd0.de yeah, I did that. For deliberate failures (a handler fails to find a template or something) it works fine. But when the user goes to a page that doesn't exist, I just get a white screen and a 404 in the console.
Is there a way I can wildcard capture all routes that don't have a handler?
Dominic
@msrd0:msrd0.de
[m]
iirc you can add a wildcard handler that calls a second router (since routers are also just handlers) and then add your middleware to the first router
Michael House
@mjhouse
@msrd0:msrd0.de that might do it.
Michael House
@mjhouse
@msrd0:msrd0.de thanks man.
Dominic
@msrd0:msrd0.de
[m]
you're welcome
Michael House
@mjhouse
@msrd0:msrd0.de It worked.
Pavan Kumar Sunkara
@pksunkara
@alsuren Hey, I remember this problem in gotham you were talking about a few months ago. https://users.rust-lang.org/t/storing-async-functions-which-have-references-possibly-hrtb-related/56262. Thought you would want to know.
1 reply
tanriol
@tanriol:matrix.org
[m]
@pksunkara: Do you remember to_async_borrowing?
Pavan Kumar Sunkara
@pksunkara
@tanriol:matrix.org No
I think this was even before that
Pavan Kumar Sunkara
@pksunkara
But yeah, I guess people were looking for that to implement the to_async_borrowing
I wasn't following 0.5.0 release since I gave up on gotham
Marwan Rabbâa
@waghanza
congrats for new release @msrd0
1 reply
Rohan Gautam
@RohanGautam
hey guys, I'm a little confused on how to pre-populate the state before handing it to a response handler. For example, use case would be if i have a mpsc channel and want to pass over a clone of the transmitter to the handler via it's state. Any thoughts/ resources you guys could point me to?
So far, seems like i would have to use middleware for it, but not sure if that's the simplest way to do it
Dominic
@msrd0:msrd0.de
[m]
if you want to put a type into the state after the router and before the request handler, you'll have to use a middleware. The easiest middleware you can use is StateMiddleware that just puts a clone of the value you initialize it with into the state for every request
tanriol
@tanriol:matrix.org
[m]
@alsuren: Thank you for the link :-)
Brian Moelk
@bmoelk
I'm hacking on my first gotham project (and new to rust), is there an example on how to unit test handlers directly?
Dominic
@msrd0:msrd0.de
[m]
@bmoelk: I think there's no such example as the recommended way to test handlers is through the test server. However, if you really want to test the handlers directly, you can use State::with_new (note that this method is public but hidden from documentation), similar to how we test route matchers: https://github.com/gotham-rs/gotham/blob/master/gotham/src/router/route/matcher/content_type.rs#L150
Note However that this means no middlewares will run (so no cookie parsing etc) and you will have to place all the required parts into the state yourself (like headers, request body, etc)
Brian Moelk
@bmoelk
ok, I attempted to use State::with_new but ran into some core Rust newbie issues trying to get it all to work properly. I gave up and started testing the full request, which I have working. But that seemed somewhat lacking because I wanted to test the actual changes made to the DB however with_test_transactions it seems that's not possible. I'll give it another go and come back with specific issues. Thanks!
Brian Moelk
@bmoelk
I don't know how to work through this issue: error[E0507]: cannot move out ofstate` which is behind a mutable reference
--> src/handlers.rs:194:36
|
194 | my_handler(
state);
| ^^^^^^ move occurs because *state has type gotham::state::State, which does not implement the Copy trait`
handler declaration like: pub fn my_handler(state: State) -> (State, impl IntoResponse) {
Dominic
@msrd0:msrd0.de
[m]
@bmoelk: Sorry, that signature is actually incompatible. This is a short example how you could do it if you really want to: https://gist.github.com/msrd0/5c6ecbfaf2934b90a3cbb0706486eb6f