Victor Chou | 7 Sep 2012 20:53
Picon

convert Network.Wai Request to Network.HTTP.Conduit Request

What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.

Victor Chou | 8 Sep 2012 03:13
Picon

Re: convert Network.Wai Request to Network.HTTP.Conduit Request

Actually, as I try to figure out how to do this convert one to the other, turns out that I don't know how to do this period, as the Conduit Request is a Request m and the Yesod Request/Wai Request is just a simple data type, and in addition, I'm running into all kinds of problems, like how to set the RequestBody m type, all of which is related to the fact that I still don't really understand Haskell yet.

Help!



On Friday, September 7, 2012 11:53:12 AM UTC-7, Victor Chou wrote:

What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.
Victor Chou | 8 Sep 2012 21:14
Picon

Re: convert Network.Wai Request to Network.HTTP.Conduit Request

nobody?  ...

On Friday, September 7, 2012 6:13:23 PM UTC-7, Victor Chou wrote:

Actually, as I try to figure out how to do this convert one to the other, turns out that I don't know how to do this period, as the Conduit Request is a Request m and the Yesod Request/Wai Request is just a simple data type, and in addition, I'm running into all kinds of problems, like how to set the RequestBody m type, all of which is related to the fact that I still don't really understand Haskell yet.

Help!



On Friday, September 7, 2012 11:53:12 AM UTC-7, Victor Chou wrote:
What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.
BJ Terry | 9 Sep 2012 07:25
Picon

Re: convert Network.Wai Request to Network.HTTP.Conduit Request

I don't think there is a single line function to do it. You have to build the request like this, as far as I can tell: http://pastebin.com/v4zSmuCa

Apologies for the general horribleness of that code. It forwards the request from whatever server receives it to google.

On Saturday, September 8, 2012 12:14:08 PM UTC-7, Victor Chou wrote:

nobody?  ...

On Friday, September 7, 2012 6:13:23 PM UTC-7, Victor Chou wrote:
Actually, as I try to figure out how to do this convert one to the other, turns out that I don't know how to do this period, as the Conduit Request is a Request m and the Yesod Request/Wai Request is just a simple data type, and in addition, I'm running into all kinds of problems, like how to set the RequestBody m type, all of which is related to the fact that I still don't really understand Haskell yet.

Help!



On Friday, September 7, 2012 11:53:12 AM UTC-7, Victor Chou wrote:
What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.
Victor Chou | 9 Sep 2012 18:47
Picon

Re: convert Network.Wai Request to Network.HTTP.Conduit Request

thanks!  i appreciate the time you took to put this together.  you have saved me countless hours!

i have a question: for a function like:

getHomeR :: Handler RepHtml

how do i stick a withManager (from Conduit) in?  like:

getHomeR = do
  withManager $ \ manager -> do ...


It keeps complaining No instance for (MonadBaseControl IO m0).  I'm guessing Handler isn't of this type, and is hence impossible to do so.  Of course, it's not all the necessary, I'm just looking at the code on the Conduit documentation.  Thanks again! 


On Saturday, September 8, 2012 10:25:56 PM UTC-7, BJ Terry wrote:

I don't think there is a single line function to do it. You have to build the request like this, as far as I can tell: http://pastebin.com/v4zSmuCa

Apologies for the general horribleness of that code. It forwards the request from whatever server receives it to google.

On Saturday, September 8, 2012 12:14:08 PM UTC-7, Victor Chou wrote:
nobody?  ...

On Friday, September 7, 2012 6:13:23 PM UTC-7, Victor Chou wrote:
Actually, as I try to figure out how to do this convert one to the other, turns out that I don't know how to do this period, as the Conduit Request is a Request m and the Yesod Request/Wai Request is just a simple data type, and in addition, I'm running into all kinds of problems, like how to set the RequestBody m type, all of which is related to the fact that I still don't really understand Haskell yet.

Help!



On Friday, September 7, 2012 11:53:12 AM UTC-7, Victor Chou wrote:
What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.
BJ Terry | 10 Sep 2012 03:38
Picon

Re: convert Network.Wai Request to Network.HTTP.Conduit Request

I think this code works.
http://pastebin.com/55gSY6aL

There is an instance of MonadBaseControl IO (GHandler sub master) defined in Yesod.Handler. I think the problem was probably somewhere else in your code. When I was working on this I ran into that error when I wasn't properly dealing with the Response that http provides within the ResourceT block. For production code of course you will probably want to use some other Sink than consume for performance I would imagine.

On Sunday, September 9, 2012 9:47:29 AM UTC-7, Victor Chou wrote:

thanks!  i appreciate the time you took to put this together.  you have saved me countless hours!

i have a question: for a function like:

getHomeR :: Handler RepHtml

how do i stick a withManager (from Conduit) in?  like:

getHomeR = do
  withManager $ \ manager -> do ...


It keeps complaining No instance for (MonadBaseControl IO m0).  I'm guessing Handler isn't of this type, and is hence impossible to do so.  Of course, it's not all the necessary, I'm just looking at the code on the Conduit documentation.  Thanks again! 


On Saturday, September 8, 2012 10:25:56 PM UTC-7, BJ Terry wrote:
I don't think there is a single line function to do it. You have to build the request like this, as far as I can tell: http://pastebin.com/v4zSmuCa

Apologies for the general horribleness of that code. It forwards the request from whatever server receives it to google.

On Saturday, September 8, 2012 12:14:08 PM UTC-7, Victor Chou wrote:
nobody?  ...

On Friday, September 7, 2012 6:13:23 PM UTC-7, Victor Chou wrote:
Actually, as I try to figure out how to do this convert one to the other, turns out that I don't know how to do this period, as the Conduit Request is a Request m and the Yesod Request/Wai Request is just a simple data type, and in addition, I'm running into all kinds of problems, like how to set the RequestBody m type, all of which is related to the fact that I still don't really understand Haskell yet.

Help!



On Friday, September 7, 2012 11:53:12 AM UTC-7, Victor Chou wrote:
What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.
Victor Chou | 10 Sep 2012 07:15
Picon

Re: convert Network.Wai Request to Network.HTTP.Conduit Request

thanks again!  i greatly appreciate it.  i'm a noob to both web programming and haskell, not to mention yesod, so i apologize for pestering people with all these questions... it's very difficult to figure out by myself what the issues are sometimes because the "potential misconception/bug space" simply grows exponentially... with practice should be getting better sooner rather than later i'm sure!  so thank you for taking the time.

- victor



On Sunday, September 9, 2012 6:38:55 PM UTC-7, BJ Terry wrote:

I think this code works.
http://pastebin.com/55gSY6aL

There is an instance of MonadBaseControl IO (GHandler sub master) defined in Yesod.Handler. I think the problem was probably somewhere else in your code. When I was working on this I ran into that error when I wasn't properly dealing with the Response that http provides within the ResourceT block. For production code of course you will probably want to use some other Sink than consume for performance I would imagine.

On Sunday, September 9, 2012 9:47:29 AM UTC-7, Victor Chou wrote:
thanks!  i appreciate the time you took to put this together.  you have saved me countless hours!

i have a question: for a function like:

getHomeR :: Handler RepHtml

how do i stick a withManager (from Conduit) in?  like:

getHomeR = do
  withManager $ \ manager -> do ...


It keeps complaining No instance for (MonadBaseControl IO m0).  I'm guessing Handler isn't of this type, and is hence impossible to do so.  Of course, it's not all the necessary, I'm just looking at the code on the Conduit documentation.  Thanks again! 


On Saturday, September 8, 2012 10:25:56 PM UTC-7, BJ Terry wrote:
I don't think there is a single line function to do it. You have to build the request like this, as far as I can tell: http://pastebin.com/v4zSmuCa

Apologies for the general horribleness of that code. It forwards the request from whatever server receives it to google.

On Saturday, September 8, 2012 12:14:08 PM UTC-7, Victor Chou wrote:
nobody?  ...

On Friday, September 7, 2012 6:13:23 PM UTC-7, Victor Chou wrote:
Actually, as I try to figure out how to do this convert one to the other, turns out that I don't know how to do this period, as the Conduit Request is a Request m and the Yesod Request/Wai Request is just a simple data type, and in addition, I'm running into all kinds of problems, like how to set the RequestBody m type, all of which is related to the fact that I still don't really understand Haskell yet.

Help!



On Friday, September 7, 2012 11:53:12 AM UTC-7, Victor Chou wrote:
What I want to do is to pass along a POST/GET message to another server.  But in the main application what I get from getRequest is a Yesod Request and waiRequest gives me a Network.Wai Request.  I think I need to pass along a Network.HTTP.Conduit Request.  Is there an easy easy to convert a WAI Request to the Conduit Request?  Thanks.

Gmane