http feature proposal: speifying which pid should receive async responses

Vincent de Phily vincent.dephily@REDACTED
Wed Jul 8 19:55:50 CEST 2009


Hi,

currently, http:request(...{sync,false}...) returns responses to the calling 
process. This is not allways convenient : sometimes we want another process 
to receive the response. It's possible work around this using spawn/receive 
machinery, but that's pointlessly painfull.

This patch adds a 'reply_pid' option to http:request(), cleanly solving the 
problem :

--- src/http.erl~    2009-06-12 12:04:35.000000000 +0200
+++ src/http.erl     2009-07-08 18:53:47.000000000 +0200
@@ -284,6 +284,7 @@

     HTTPRecordOptions = http_options(HTTPOptions, #http_options{}),
     Sync = proplists:get_value(sync, Options, true),
+    ReplyPid = proplists:get_value(reply_pid, Options, self()),
     NewHeaders = lists:map(fun({Key, Val}) ->
                                   {http_util:to_lower(Key), Val} end,
                           Headers),
@@ -296,7 +297,7 @@
        _ ->
            RecordHeaders = header_record(NewHeaders, #http_request_h{},
                                          Host, Version),
-           Request = #request{from = self(),
+           Request = #request{from = ReplyPid,
                               scheme = Scheme,
                               address = {Host,Port},
                               path = Path,


The documentation would need to be updated too, but I'm not sure where to 
patch that.

-- 
Vincent de Phily
Mobile Devices
+33 (0) 666 301 306
+33 (0) 142 119 325

Warning
This message (and any associated files) is intended only for the use of its
intended recipient and may contain information that is confidential, subject
to copyright or constitutes a trade secret. If you are not the intended
recipient you are hereby notified that any dissemination, copying or
distribution of this message, or files associated with this message, is
strictly prohibited. If you have received this message in error, please
notify us immediately by replying to the message and deleting it from your
computer. Any views or opinions presented are solely those of the author
vincent.dephily@REDACTED and do not necessarily represent those of 
the
company. Although the company has taken reasonable precautions to ensure no
viruses are present in this email, the company cannot accept responsibility
for any loss or damage arising from the use of this email or attachments.


More information about the erlang-questions mailing list