You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@trafficserver.apache.org by Servalan eq <se...@hotmail.com> on 2012/04/05 16:27:14 UTC

RE: using curl during an http transaction



Hi Erik, did you ever get this TSHttpConnect call working?
I too am looking for some good examples to call a seperate HTTP service while processing a request to determine how to handle it.
thanks very much,
Servalan

> On 04/20/2011 02:16 PM, Earle, Erik wrote:

> Is there an example usage of TSHttpConnect somewhere?  I did not
see any in the examples.

 

 

-- 

Erik
Earle     206.664.4016     tie line:
8.664.4016     erik.earle@disney.com

Walt
Disney Connected and Advanced Technologies 

925 4th Ave - Suite 1600 - Seattle - 98104 

 

From: Leif Hedstrom
[mailto:zwoop@apache.org] 

Sent: Wednesday, April 20, 2011 2:33 PM

To: users@trafficserver.apache.org

Cc: Earle, Erik

Subject: Re: using curl during an http transaction

 

On
04/20/2011 02:16 PM, Earle, Erik wrote: 

Hi
all.   I’m new to the list and trafficserver.

 

I’m
building a plugin to do OAuth 2.  I’m looking to make a call to a separate
(REST) service to do the OAuth token validation.  

 

Does anyone
have experience with using something like curl or vconnections, etc… to make a
separate http request during an http transaction?  

 



You want to use the appropriate APIs that we provide to perform HTTP requests,
e.g. TSNetConnect() or TSHttpConnect().



-- leif 		 	   		  

RE: using curl during an http transaction

Posted by Servalan eq <se...@hotmail.com>.
Hi there.I am putting together a plugin based on the protocol and redirect-1 examples but I am getting a null response from myTSUrlHostGetcall.  TSHttpTxnClientReqGet, TSHttpHdrUrlGet and TSUrlPathGet work fine, but the host response is null.If I call TSUrlHostSet first then I can retrieve the value, but not otherwise. Is there some setting I need to allow the host to be visible to my plugin?
I have just added the plugin to my plugins.config file and am setting a hook on 
TS_EVENT_HTTP_READ_REQUEST_HDR
thanks for any tips.
Servalan

----------------------------------------
&#62; From&#58; Peter.Walsh&#64;disney.com&#13;&#10;&#62; To&#58; users&#64;trafficserver.apache.org&#13;&#10;&#62; Date&#58; Thu, 5 Apr 2012 09&#58;57&#58;15 -0700&#13;&#10;&#62; Subject&#58; RE&#58; using curl during an http transaction&#13;&#10;&#62;&#13;&#10;&#62; Hello,&#13;&#10;&#62; I worked with Erik on this, and we did get it working eventually. It was quite difficult to get this working as there aren&#39;t any good examples, but we pieced together what we could based on the InkAPITest class and the example protocol plugin that uses TSNetConnect, which is somewhat similar.&#13;&#10;&#62;&#13;&#10;&#62; I&#39;m a bit swamped right now, but when I have a minute I&#39;ll post a response to this with some helpful tips, gotchas, etc.&#13;&#10;&#62;&#13;&#10;&#62; -Pete&#13;&#10;&#62;&#13;&#10;&#62; -----Original Message-----&#13;&#10;&#62; From&#58; Servalan eq &#91;mailto&#58;servalaneq&#64;hotmail.com&#93;&#13;&#10;&#62; Sent&#58; Thursday, April 05, 2012 7&#58;27 AM&#13;&#10;&#62; To&#58; users&#64;trafficserver.apache.org&#13;&#10;&#62; Subject&#58; RE&#58; using curl during an http transaction&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; Hi Erik, did you ever get this TSHttpConnect call working&#63;&#13;&#10;&#62; I too am looking for some good examples to call a seperate HTTP service while processing a request to determine how to handle it.&#13;&#10;&#62; thanks very much,&#13;&#10;&#62; Servalan&#13;&#10;&#62;&#13;&#10;&#62; &#62; On 04/20/2011 02&#58;16 PM, Earle, Erik wrote&#58;&#13;&#10;&#62;&#13;&#10;&#62; &#62; Is there an example usage of TSHttpConnect somewhere&#63;  I did not&#13;&#10;&#62; see any in the examples.&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; --&#13;&#10;&#62;&#13;&#10;&#62; Erik&#13;&#10;&#62; Earle     206.664.4016     tie line&#58;&#13;&#10;&#62; 8.664.4016     erik.earle&#64;disney.com&#13;&#10;&#62;&#13;&#10;&#62; Walt&#13;&#10;&#62; Disney Connected and Advanced Technologies&#13;&#10;&#62;&#13;&#10;&#62; 925 4th Ave - Suite 1600 - Seattle - 98104&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; From&#58; Leif Hedstrom&#13;&#10;&#62; &#91;mailto&#58;zwoop&#64;apache.org&#93;&#13;&#10;&#62;&#13;&#10;&#62; Sent&#58; Wednesday, April 20, 2011 2&#58;33 PM&#13;&#10;&#62;&#13;&#10;&#62; To&#58; users&#64;trafficserver.apache.org&#13;&#10;&#62;&#13;&#10;&#62; Cc&#58; Earle, Erik&#13;&#10;&#62;&#13;&#10;&#62; Subject&#58; Re&#58; using curl during an http transaction&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; On&#13;&#10;&#62; 04/20/2011 02&#58;16 PM, Earle, Erik wrote&#58;&#13;&#10;&#62;&#13;&#10;&#62; Hi&#13;&#10;&#62; all.   I&#39;m new to the list and trafficserver.&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; I&#39;m&#13;&#10;&#62; building a plugin to do OAuth 2.  I&#39;m looking to make a call to a separate&#13;&#10;&#62; &#40;REST&#41; service to do the OAuth token validation.&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; Does anyone&#13;&#10;&#62; have experience with using something like curl or vconnections, etc. to make a&#13;&#10;&#62; separate http request during an http transaction&#63;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; You want to use the appropriate APIs that we provide to perform HTTP requests,&#13;&#10;&#62; e.g. TSNetConnect&#40;&#41; or TSHttpConnect&#40;&#41;.&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62;&#13;&#10;&#62; -- leif&#13;&#10; 		 	   		  

Re: using curl during an http transaction

Posted by Brian Geffon <br...@gmail.com>.
I think the FetchSM.cc could also be a good example of using
TSHttpConnect()?

Brian

On Thu, Apr 5, 2012 at 11:18 AM, Servalan eq <se...@hotmail.com> wrote:

>
>
> > Date: Thu, 5 Apr 2012 11:33:37 -0600
> > From: zwoop@apache.org
> > To: users@trafficserver.apache.org
> > CC: Peter.Walsh@disney.com
>
> > Subject: Re: using curl during an http transaction
> >
> > On 4/5/12 10:57 AM, Walsh, Peter wrote:
> > > Hello,
> > > I worked with Erik on this, and we did get it working eventually. It
> was quite difficult to get this working as there aren't any good examples,
> but we pieced together what we could based on the InkAPITest class and the
> example protocol plugin that uses TSNetConnect, which is somewhat similar.
> >
> > You should update the documentation! :-).
> >
> > >
> > > I'm a bit swamped right now, but when I have a minute I'll post a
> response to this with some helpful tips, gotchas, etc.
> > >
> >
> > Cool. A Wiki page could be useful too, things tends to get lost in email
> > (i.e. people dont' search the archives).
> >
> > Cheers!
> >
> > -- Leif
> >
>
> That would be great.
> If (when surely) I get it working I'd be happy to add to the docs /
> examples.
>
> thanks,
> Servalan
>

RE: using curl during an http transaction

Posted by Servalan eq <se...@hotmail.com>.


> Date: Thu, 5 Apr 2012 11:33:37 -0600
> From: zwoop@apache.org
> To: users@trafficserver.apache.org
> CC: Peter.Walsh@disney.com
> Subject: Re: using curl during an http transaction
> 
> On 4/5/12 10:57 AM, Walsh, Peter wrote:
> > Hello,
> > I worked with Erik on this, and we did get it working eventually.  It was quite difficult to get this working as there aren't any good examples, but we pieced together what we could based on the InkAPITest class and the example protocol plugin that uses TSNetConnect, which is somewhat similar.
> 
> You should update the documentation! :-).
> 
> >
> > I'm a bit swamped right now, but when I have a minute I'll post a response to this with some helpful tips, gotchas, etc.
> >
> 
> Cool. A Wiki page could be useful too, things tends to get lost in email 
> (i.e. people dont' search the archives).
> 
> Cheers!
> 
> -- Leif
> 

That would be great. If (when surely) I get it working I'd be happy to add to the docs / examples.
thanks,Servalan 		 	   		  

Re: using curl during an http transaction

Posted by Leif Hedstrom <zw...@apache.org>.
On 4/5/12 10:57 AM, Walsh, Peter wrote:
> Hello,
> I worked with Erik on this, and we did get it working eventually.  It was quite difficult to get this working as there aren't any good examples, but we pieced together what we could based on the InkAPITest class and the example protocol plugin that uses TSNetConnect, which is somewhat similar.

You should update the documentation! :-).

>
> I'm a bit swamped right now, but when I have a minute I'll post a response to this with some helpful tips, gotchas, etc.
>

Cool. A Wiki page could be useful too, things tends to get lost in email 
(i.e. people dont' search the archives).

Cheers!

-- Leif


RE: using curl during an http transaction

Posted by Servalan eq <se...@hotmail.com>.
Ah thanks. I have seen this with the multiple chunks - at this stage I am only expecting tens of bytes, but it's a good idea to be careful.
thanks

From: Peter.Walsh@disney.com
To: users@trafficserver.apache.org
Date: Fri, 13 Apr 2012 08:48:00 -0700
Subject: Re: using curl during an http transaction



I'm not sure for the redirect question because we don't use that feature.  
However, one last thing I want to mention with regard to HttpConnect. Make sure to test this with large responses because its possible to get multiple READ_READY/COMPLETE callbacks when the response size is large. Many examples we've seen don't handle this correctly and we stumbled on it at first.
From:  Servalan eq <se...@hotmail.com>
Reply-To:  "users@trafficserver.apache.org" <us...@trafficserver.apache.org>
Date:  Fri, 13 Apr 2012 08:31:33 -0700
To:  "users@trafficserver.apache.org" <us...@trafficserver.apache.org>
Subject:  RE: using curl during an http transaction


Thanks very much Peter.I have got this working pretty much as you describe - I just need to go back to doing the remap type operations from a remap plugin now.
I presume I can do forwarding or redirection pretty much as normal using TSUrlHostSet, TSUrlPathSet etc.The one thing I can't see how do to is the equivalent of 
        rri->redirect = 1   on the TSRemapRequestInfo, as I can't see how to get access to this from a standard plugin event.
thanks very much for your help.
Servalan
> From: Peter.Walsh@disney.com
> To: users@trafficserver.apache.org
> Date: Thu, 12 Apr 2012 11:04:46 -0700
> Subject: Re: using curl during an http transaction
> 
> Hello,
> You may have already gotten this working, but here's some basic steps...
> 
> 1.) Call TSHttpConnect with a sockaddr object, which returns a TSVConn
> 2.) Call TSVConnWrite using the returned TSVConn, a continuation, a buffer
> reader containing your request, and the content length. This returns a
> TSVIO
> 
> example: 
> 
> RequestVio = TSVConnWrite(vconn, contp,
>                     mServerRequestBufferReader,
> TSIOBufferReaderAvail(mServerRequestBufferReader));
> 
> NOTE: There are different ways to get the URI into
> mServerRequestBufferReader, we used the ATS API's to create a new HTTP
> header, set all the fields (ie scheme, host, path, etc) and used the
> TSHttpHdrPrint to get the buffer into mServerRequestBufferReader.
> 
> 3.) Your handler will get called back with
> TS_EVENT_VCONN_WRITE_READY/COMPLETE. Once its complete, you can initiate a
> read using TSVConnRead on the TSVConn returned in step 1, and a response
> buffer, and the size of data you want.
> 
> Example: TSVConnRead(vconn, contp, >mServerResponseBuffer, INT_MAX);
> 
> This returns a new Response TSVIO
> 
> 4.) Once you've initiated the read, your handler will get called back with
> TS_EVENT_VCONN_READ_READY/COMPLETE events, at which point you can read
> data from the response buffer. This is just like the reading done in the
> transform plugins, so if you look at those you'll find tons of examples
> 
> Hope that helps
> 
> -Pete
> 
> 
> On 4/5/12 9:57 AM, "Walsh, Peter" <Pe...@disney.com> wrote:
> 
> >Hello,
> >I worked with Erik on this, and we did get it working eventually.  It was
> >quite difficult to get this working as there aren't any good examples,
> >but we pieced together what we could based on the InkAPITest class and
> >the example protocol plugin that uses TSNetConnect, which is somewhat
> >similar.  
> >
> >I'm a bit swamped right now, but when I have a minute I'll post a
> >response to this with some helpful tips, gotchas, etc.
> >
> >-Pete 
> >
> >-----Original Message-----
> >From: Servalan eq [mailto:servalaneq@hotmail.com]
> >Sent: Thursday, April 05, 2012 7:27 AM
> >To: users@trafficserver.apache.org
> >Subject: RE: using curl during an http transaction
> >
> >
> >
> >
> >Hi Erik, did you ever get this TSHttpConnect call working?
> >I too am looking for some good examples to call a seperate HTTP service
> >while processing a request to determine how to handle it.
> >thanks very much,
> >Servalan
> >
> >> On 04/20/2011 02:16 PM, Earle, Erik wrote:
> >
> >> Is there an example usage of TSHttpConnect somewhere?  I did not
> >see any in the examples.
> >
> > 
> >
> > 
> >
> >-- 
> >
> >Erik
> >Earle     206.664.4016     tie line:
> >8.664.4016     erik.earle@disney.com
> >
> >Walt
> >Disney Connected and Advanced Technologies
> >
> >925 4th Ave - Suite 1600 - Seattle - 98104
> >
> > 
> >
> >From: Leif Hedstrom
> >[mailto:zwoop@apache.org]
> >
> >Sent: Wednesday, April 20, 2011 2:33 PM
> >
> >To: users@trafficserver.apache.org
> >
> >Cc: Earle, Erik
> >
> >Subject: Re: using curl during an http transaction
> >
> > 
> >
> >On
> >04/20/2011 02:16 PM, Earle, Erik wrote:
> >
> >Hi
> >all.   I'm new to the list and trafficserver.
> >
> > 
> >
> >I'm
> >building a plugin to do OAuth 2.  I'm looking to make a call to a separate
> >(REST) service to do the OAuth token validation.
> >
> > 
> >
> >Does anyone
> >have experience with using something like curl or vconnections, etc. to
> >make a
> >separate http request during an http transaction?
> >
> > 
> >
> >
> >
> >You want to use the appropriate APIs that we provide to perform HTTP
> >requests,
> >e.g. TSNetConnect() or TSHttpConnect().
> >
> >
> >
> >-- leif 		 	   		  
> 
 		 	   		   		 	   		  

Re: using curl during an http transaction

Posted by "Walsh, Peter" <Pe...@disney.com>.
I'm not sure for the redirect question because we don't use that feature.

However, one last thing I want to mention with regard to HttpConnect. Make sure to test this with large responses because its possible to get multiple READ_READY/COMPLETE callbacks when the response size is large. Many examples we've seen don't handle this correctly and we stumbled on it at first.

From: Servalan eq <se...@hotmail.com>>
Reply-To: "users@trafficserver.apache.org<ma...@trafficserver.apache.org>" <us...@trafficserver.apache.org>>
Date: Fri, 13 Apr 2012 08:31:33 -0700
To: "users@trafficserver.apache.org<ma...@trafficserver.apache.org>" <us...@trafficserver.apache.org>>
Subject: RE: using curl during an http transaction


Thanks very much Peter.
I have got this working pretty much as you describe - I just need to go back to doing the remap type operations from a remap plugin now.

I presume I can do forwarding or redirection pretty much as normal using TSUrlHostSet, TSUrlPathSet etc.
The one thing I can't see how do to is the equivalent of

rri->redirect = 1
on the TSRemapRequestInfo, as I can't see how to get access to this from a standard plugin event.

thanks very much for your help.

Servalan

> From: Peter.Walsh@disney.com<ma...@disney.com>
> To: users@trafficserver.apache.org<ma...@trafficserver.apache.org>
> Date: Thu, 12 Apr 2012 11:04:46 -0700
> Subject: Re: using curl during an http transaction
>
> Hello,
> You may have already gotten this working, but here's some basic steps...
>
> 1.) Call TSHttpConnect with a sockaddr object, which returns a TSVConn
> 2.) Call TSVConnWrite using the returned TSVConn, a continuation, a buffer
> reader containing your request, and the content length. This returns a
> TSVIO
>
> example:
>
> RequestVio = TSVConnWrite(vconn, contp,
> mServerRequestBufferReader,
> TSIOBufferReaderAvail(mServerRequestBufferReader));
>
> NOTE: There are different ways to get the URI into
> mServerRequestBufferReader, we used the ATS API's to create a new HTTP
> header, set all the fields (ie scheme, host, path, etc) and used the
> TSHttpHdrPrint to get the buffer into mServerRequestBufferReader.
>
> 3.) Your handler will get called back with
> TS_EVENT_VCONN_WRITE_READY/COMPLETE. Once its complete, you can initiate a
> read using TSVConnRead on the TSVConn returned in step 1, and a response
> buffer, and the size of data you want.
>
> Example: TSVConnRead(vconn, contp, >mServerResponseBuffer, INT_MAX);
>
> This returns a new Response TSVIO
>
> 4.) Once you've initiated the read, your handler will get called back with
> TS_EVENT_VCONN_READ_READY/COMPLETE events, at which point you can read
> data from the response buffer. This is just like the reading done in the
> transform plugins, so if you look at those you'll find tons of examples
>
> Hope that helps
>
> -Pete
>
>
> On 4/5/12 9:57 AM, "Walsh, Peter" <Pe...@disney.com>> wrote:
>
> >Hello,
> >I worked with Erik on this, and we did get it working eventually. It was
> >quite difficult to get this working as there aren't any good examples,
> >but we pieced together what we could based on the InkAPITest class and
> >the example protocol plugin that uses TSNetConnect, which is somewhat
> >similar.
> >
> >I'm a bit swamped right now, but when I have a minute I'll post a
> >response to this with some helpful tips, gotchas, etc.
> >
> >-Pete
> >
> >-----Original Message-----
> >From: Servalan eq [mailto:servalaneq@hotmail.com]
> >Sent: Thursday, April 05, 2012 7:27 AM
> >To: users@trafficserver.apache.org<ma...@trafficserver.apache.org>
> >Subject: RE: using curl during an http transaction
> >
> >
> >
> >
> >Hi Erik, did you ever get this TSHttpConnect call working?
> >I too am looking for some good examples to call a seperate HTTP service
> >while processing a request to determine how to handle it.
> >thanks very much,
> >Servalan
> >
> >> On 04/20/2011 02:16 PM, Earle, Erik wrote:
> >
> >> Is there an example usage of TSHttpConnect somewhere? I did not
> >see any in the examples.
> >
> >
> >
> >
> >
> >--
> >
> >Erik
> >Earle 206.664.4016 tie line:
> >8.664.4016 erik.earle@disney.com<ma...@disney.com>
> >
> >Walt
> >Disney Connected and Advanced Technologies
> >
> >925 4th Ave - Suite 1600 - Seattle - 98104
> >
> >
> >
> >From: Leif Hedstrom
> >[mailto:zwoop@apache.org]
> >
> >Sent: Wednesday, April 20, 2011 2:33 PM
> >
> >To: users@trafficserver.apache.org<ma...@trafficserver.apache.org>
> >
> >Cc: Earle, Erik
> >
> >Subject: Re: using curl during an http transaction
> >
> >
> >
> >On
> >04/20/2011 02:16 PM, Earle, Erik wrote:
> >
> >Hi
> >all. I'm new to the list and trafficserver.
> >
> >
> >
> >I'm
> >building a plugin to do OAuth 2. I'm looking to make a call to a separate
> >(REST) service to do the OAuth token validation.
> >
> >
> >
> >Does anyone
> >have experience with using something like curl or vconnections, etc. to
> >make a
> >separate http request during an http transaction?
> >
> >
> >
> >
> >
> >You want to use the appropriate APIs that we provide to perform HTTP
> >requests,
> >e.g. TSNetConnect() or TSHttpConnect().
> >
> >
> >
> >-- leif
>

RE: using curl during an http transaction

Posted by Servalan eq <se...@hotmail.com>.

Thanks very much Peter.I have got this working pretty much as you describe - I just need to go back to doing the remap type operations from a remap plugin now.
I presume I can do forwarding or redirection pretty much as normal using TSUrlHostSet, TSUrlPathSet etc.The one thing I can't see how do to is the equivalent of 
        rri->redirect = 1   on the TSRemapRequestInfo, as I can't see how to get access to this from a standard plugin event.
thanks very much for your help.
Servalan
> From: Peter.Walsh@disney.com
> To: users@trafficserver.apache.org
> Date: Thu, 12 Apr 2012 11:04:46 -0700
> Subject: Re: using curl during an http transaction
> 
> Hello,
> You may have already gotten this working, but here's some basic steps...
> 
> 1.) Call TSHttpConnect with a sockaddr object, which returns a TSVConn
> 2.) Call TSVConnWrite using the returned TSVConn, a continuation, a buffer
> reader containing your request, and the content length. This returns a
> TSVIO
> 
> example: 
> 
> RequestVio = TSVConnWrite(vconn, contp,
>                     mServerRequestBufferReader,
> TSIOBufferReaderAvail(mServerRequestBufferReader));
> 
> NOTE: There are different ways to get the URI into
> mServerRequestBufferReader, we used the ATS API's to create a new HTTP
> header, set all the fields (ie scheme, host, path, etc) and used the
> TSHttpHdrPrint to get the buffer into mServerRequestBufferReader.
> 
> 3.) Your handler will get called back with
> TS_EVENT_VCONN_WRITE_READY/COMPLETE. Once its complete, you can initiate a
> read using TSVConnRead on the TSVConn returned in step 1, and a response
> buffer, and the size of data you want.
> 
> Example: TSVConnRead(vconn, contp, >mServerResponseBuffer, INT_MAX);
> 
> This returns a new Response TSVIO
> 
> 4.) Once you've initiated the read, your handler will get called back with
> TS_EVENT_VCONN_READ_READY/COMPLETE events, at which point you can read
> data from the response buffer. This is just like the reading done in the
> transform plugins, so if you look at those you'll find tons of examples
> 
> Hope that helps
> 
> -Pete
> 
> 
> On 4/5/12 9:57 AM, "Walsh, Peter" <Pe...@disney.com> wrote:
> 
> >Hello,
> >I worked with Erik on this, and we did get it working eventually.  It was
> >quite difficult to get this working as there aren't any good examples,
> >but we pieced together what we could based on the InkAPITest class and
> >the example protocol plugin that uses TSNetConnect, which is somewhat
> >similar.  
> >
> >I'm a bit swamped right now, but when I have a minute I'll post a
> >response to this with some helpful tips, gotchas, etc.
> >
> >-Pete 
> >
> >-----Original Message-----
> >From: Servalan eq [mailto:servalaneq@hotmail.com]
> >Sent: Thursday, April 05, 2012 7:27 AM
> >To: users@trafficserver.apache.org
> >Subject: RE: using curl during an http transaction
> >
> >
> >
> >
> >Hi Erik, did you ever get this TSHttpConnect call working?
> >I too am looking for some good examples to call a seperate HTTP service
> >while processing a request to determine how to handle it.
> >thanks very much,
> >Servalan
> >
> >> On 04/20/2011 02:16 PM, Earle, Erik wrote:
> >
> >> Is there an example usage of TSHttpConnect somewhere?  I did not
> >see any in the examples.
> >
> > 
> >
> > 
> >
> >-- 
> >
> >Erik
> >Earle     206.664.4016     tie line:
> >8.664.4016     erik.earle@disney.com
> >
> >Walt
> >Disney Connected and Advanced Technologies
> >
> >925 4th Ave - Suite 1600 - Seattle - 98104
> >
> > 
> >
> >From: Leif Hedstrom
> >[mailto:zwoop@apache.org]
> >
> >Sent: Wednesday, April 20, 2011 2:33 PM
> >
> >To: users@trafficserver.apache.org
> >
> >Cc: Earle, Erik
> >
> >Subject: Re: using curl during an http transaction
> >
> > 
> >
> >On
> >04/20/2011 02:16 PM, Earle, Erik wrote:
> >
> >Hi
> >all.   I'm new to the list and trafficserver.
> >
> > 
> >
> >I'm
> >building a plugin to do OAuth 2.  I'm looking to make a call to a separate
> >(REST) service to do the OAuth token validation.
> >
> > 
> >
> >Does anyone
> >have experience with using something like curl or vconnections, etc. to
> >make a
> >separate http request during an http transaction?
> >
> > 
> >
> >
> >
> >You want to use the appropriate APIs that we provide to perform HTTP
> >requests,
> >e.g. TSNetConnect() or TSHttpConnect().
> >
> >
> >
> >-- leif 		 	   		  
> 
 		 	   		  

Re: using curl during an http transaction

Posted by "Walsh, Peter" <Pe...@disney.com>.
Hello,
You may have already gotten this working, but here's some basic steps...

1.) Call TSHttpConnect with a sockaddr object, which returns a TSVConn
2.) Call TSVConnWrite using the returned TSVConn, a continuation, a buffer
reader containing your request, and the content length. This returns a
TSVIO

example: 

RequestVio = TSVConnWrite(vconn, contp,
                    mServerRequestBufferReader,
TSIOBufferReaderAvail(mServerRequestBufferReader));

NOTE: There are different ways to get the URI into
mServerRequestBufferReader, we used the ATS API's to create a new HTTP
header, set all the fields (ie scheme, host, path, etc) and used the
TSHttpHdrPrint to get the buffer into mServerRequestBufferReader.

3.) Your handler will get called back with
TS_EVENT_VCONN_WRITE_READY/COMPLETE. Once its complete, you can initiate a
read using TSVConnRead on the TSVConn returned in step 1, and a response
buffer, and the size of data you want.

Example: TSVConnRead(vconn, contp, >mServerResponseBuffer, INT_MAX);

This returns a new Response TSVIO

4.) Once you've initiated the read, your handler will get called back with
TS_EVENT_VCONN_READ_READY/COMPLETE events, at which point you can read
data from the response buffer. This is just like the reading done in the
transform plugins, so if you look at those you'll find tons of examples

Hope that helps

-Pete


On 4/5/12 9:57 AM, "Walsh, Peter" <Pe...@disney.com> wrote:

>Hello,
>I worked with Erik on this, and we did get it working eventually.  It was
>quite difficult to get this working as there aren't any good examples,
>but we pieced together what we could based on the InkAPITest class and
>the example protocol plugin that uses TSNetConnect, which is somewhat
>similar.  
>
>I'm a bit swamped right now, but when I have a minute I'll post a
>response to this with some helpful tips, gotchas, etc.
>
>-Pete 
>
>-----Original Message-----
>From: Servalan eq [mailto:servalaneq@hotmail.com]
>Sent: Thursday, April 05, 2012 7:27 AM
>To: users@trafficserver.apache.org
>Subject: RE: using curl during an http transaction
>
>
>
>
>Hi Erik, did you ever get this TSHttpConnect call working?
>I too am looking for some good examples to call a seperate HTTP service
>while processing a request to determine how to handle it.
>thanks very much,
>Servalan
>
>> On 04/20/2011 02:16 PM, Earle, Erik wrote:
>
>> Is there an example usage of TSHttpConnect somewhere?  I did not
>see any in the examples.
>
> 
>
> 
>
>-- 
>
>Erik
>Earle     206.664.4016     tie line:
>8.664.4016     erik.earle@disney.com
>
>Walt
>Disney Connected and Advanced Technologies
>
>925 4th Ave - Suite 1600 - Seattle - 98104
>
> 
>
>From: Leif Hedstrom
>[mailto:zwoop@apache.org]
>
>Sent: Wednesday, April 20, 2011 2:33 PM
>
>To: users@trafficserver.apache.org
>
>Cc: Earle, Erik
>
>Subject: Re: using curl during an http transaction
>
> 
>
>On
>04/20/2011 02:16 PM, Earle, Erik wrote:
>
>Hi
>all.   I'm new to the list and trafficserver.
>
> 
>
>I'm
>building a plugin to do OAuth 2.  I'm looking to make a call to a separate
>(REST) service to do the OAuth token validation.
>
> 
>
>Does anyone
>have experience with using something like curl or vconnections, etc. to
>make a
>separate http request during an http transaction?
>
> 
>
>
>
>You want to use the appropriate APIs that we provide to perform HTTP
>requests,
>e.g. TSNetConnect() or TSHttpConnect().
>
>
>
>-- leif 		 	   		  


RE: using curl during an http transaction

Posted by "Walsh, Peter" <Pe...@disney.com>.
Hello,
I worked with Erik on this, and we did get it working eventually.  It was quite difficult to get this working as there aren't any good examples, but we pieced together what we could based on the InkAPITest class and the example protocol plugin that uses TSNetConnect, which is somewhat similar.  

I'm a bit swamped right now, but when I have a minute I'll post a response to this with some helpful tips, gotchas, etc.

-Pete 

-----Original Message-----
From: Servalan eq [mailto:servalaneq@hotmail.com] 
Sent: Thursday, April 05, 2012 7:27 AM
To: users@trafficserver.apache.org
Subject: RE: using curl during an http transaction




Hi Erik, did you ever get this TSHttpConnect call working?
I too am looking for some good examples to call a seperate HTTP service while processing a request to determine how to handle it.
thanks very much,
Servalan

> On 04/20/2011 02:16 PM, Earle, Erik wrote:

> Is there an example usage of TSHttpConnect somewhere?  I did not
see any in the examples.

 

 

-- 

Erik
Earle     206.664.4016     tie line:
8.664.4016     erik.earle@disney.com

Walt
Disney Connected and Advanced Technologies 

925 4th Ave - Suite 1600 - Seattle - 98104 

 

From: Leif Hedstrom
[mailto:zwoop@apache.org] 

Sent: Wednesday, April 20, 2011 2:33 PM

To: users@trafficserver.apache.org

Cc: Earle, Erik

Subject: Re: using curl during an http transaction

 

On
04/20/2011 02:16 PM, Earle, Erik wrote: 

Hi
all.   I'm new to the list and trafficserver.

 

I'm
building a plugin to do OAuth 2.  I'm looking to make a call to a separate
(REST) service to do the OAuth token validation.  

 

Does anyone
have experience with using something like curl or vconnections, etc. to make a
separate http request during an http transaction?  

 



You want to use the appropriate APIs that we provide to perform HTTP requests,
e.g. TSNetConnect() or TSHttpConnect().



-- leif