Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 90D459EB2 for ; Sat, 23 Jun 2012 10:51:01 +0000 (UTC) Received: (qmail 70213 invoked by uid 500); 23 Jun 2012 10:51:01 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 69928 invoked by uid 500); 23 Jun 2012 10:51:00 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 69897 invoked by uid 99); 23 Jun 2012 10:50:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jun 2012 10:50:59 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ohaya@cox.net designates 68.230.241.218 as permitted sender) Received: from [68.230.241.218] (HELO eastrmfepo203.cox.net) (68.230.241.218) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jun 2012 10:50:51 +0000 Received: from eastrmimpo210.cox.net ([68.230.241.225]) by eastrmfepo203.cox.net (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP id <20120623105030.SRR18532.eastrmfepo203.cox.net@eastrmimpo210.cox.net>; Sat, 23 Jun 2012 06:50:30 -0400 Received: from eastrmwml113 ([172.18.18.217]) by eastrmimpo210.cox.net with bizsmtp id RmqW1j0014h0NJL02mqWri; Sat, 23 Jun 2012 06:50:30 -0400 X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020208.4FE59F76.0024,ss=1,re=0.000,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=1.1 cv=dW166oI5E3VWoXuUpr+q8axZtXMQIgkkR45LP3Vo3E4= c=1 sm=1 a=dsUbt0ny_PoA:10 a=G8Uczd0VNMoA:10 a=X0LLrcwhTTAA:10 a=IkcTkHD0fZMA:10 a=TRy/vagDvAN6zvr8h90PzQ==:17 a=pGLkceISAAAA:8 a=kviXuzpPAAAA:8 a=1XWaLZrsAAAA:8 a=UxVg9iHiSpS3IBtM-qsA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 a=4vB-4DCPJfMA:10 a=TRy/vagDvAN6zvr8h90PzQ==:117 X-CM-Score: 0.00 Authentication-Results: cox.net; none Received: from 72.192.248.102 by webmail.east.cox.net; Sat, 23 Jun 2012 6:50:29 -0400 Message-ID: <20120623065030.CW869.205153.imail@eastrmwml113> Date: Sat, 23 Jun 2012 6:50:30 -0400 From: To: modules-dev@httpd.apache.org Subject: Re: Anyone have some example code doing simple HTTP GET request from within a module? Cc: Sorin Manolache In-Reply-To: <4FE570AB.1060005@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) Sensitivity: Normal X-Virus-Checked: Checked by ClamAV on apache.org ---- Sorin Manolache wrote: > On 2012-06-23 04:47, ohaya@cox.net wrote: > > Hi, > > > > Per earlier threads on this list, I've been working on an Apache module. For the time being, I'm kind of stuck because of the problems that I've run into with trying to integrate my module with a 3rd party library, so just for my module, which is mainly a proof-of-concept, I'd like to have my module do an HTTP GET request. > > > > So, I was wondering if anyone has some simple example code for doing that from within a module, maybe using libcurl, or just natively using sockets? > > > > I'm trying to do this myself, and I've been looking at using libcurl, but most of the examples that I've seen use the "easy" setup, so if someone has something like that that can be shared, it'd be a big help. Conversely, if I figure it out, I'll post some working snippets here :)... > > > I'll say the same thing as Ben, try with apache, either mod_proxy or > ap_run_sub_request. That if you make one outgoing request per incoming > request. If you want several outgoing requests, in parallel preferably, > per incoming request, then go with some 3rd-party library. > > I have some in-house C++ wrappers for libcurl (curl_multi_* + timeouts + > client pools), but they are not straightforward to use, a lot of setup > is involved, and they are not thoroughly tested. > > S Sorin and Ben, I'll take a look at mod_proxy.c later, but, FYI, I just tried the following: - I added the following to my tweaked mod_headers.c: #include "curl/curl.h" . . . void callCurl() { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com"); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); } return; } - I compiled with apxs, with no additonal -L or -l - I added a call to callCurl() in my code where I knew it'd get called. - In my httpd.conf, I added in front of the LoadModule for mod_headers: LoadFile /usr/lib64/libcurl.so.3.0.0 Then I started Apache in single process (-k start -X), and it started, and then I tested, and it worked!! For this prototype, I'll try to see if I can get this to the point that I confirm what I'm doing, then I'll go back and look at mod_proxy.c to maybe do native HTTP GET. Thanks, Jim