1.2.0 permalink Arrow_down_16x16
  • (http-agent uri & options)
Creates (and immediately returns) an Agent representing an HTTP
request running in a new thread.

options are key/value pairs:

:method string

The HTTP method name. Default is "GET".

:headers h

HTTP headers, as a Map or a sequence of pairs like
([key1,value1], [key2,value2]) Default is nil.

:body b

HTTP request entity body, one of nil, String, byte[], InputStream,
Reader, or File. Default is nil.

:connect-timeout int

Timeout value, in milliseconds, when opening a connection to the
URL. Default is zero, meaning no timeout.

:read-timeout int

Timeout value, in milliseconds, when reading data from the
connection. Default is zero, meaning no timeout.

:follow-redirects boolean

If true, HTTP 3xx redirects will be followed automatically. Default
is true.

:handler f

Function to be called when the HTTP response body is ready. If you
do not provide a handler function, the default is to buffer the
entire response body in memory.

The handler function will be called with the HTTP agent as its
argument, and can use the 'stream' function to read the response
body. The return value of this function will be stored in the state
of the agent and can be retrieved with the 'result' function. Any
exceptions thrown by this function will be added to the agent's
error queue (see agent-errors). The default function collects the
response stream in a memory buffer.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/http/agent.clj:175 top

(defn http-agent
  "Creates (and immediately returns) an Agent representing an HTTP
  request running in a new thread.

  options are key/value pairs:

  :method string

  The HTTP method name.  Default is \"GET\".

  :headers h

  HTTP headers, as a Map or a sequence of pairs like 
  ([key1,value1], [key2,value2])  Default is nil.

  :body b
  
  HTTP request entity body, one of nil, String, byte[], InputStream,
  Reader, or File.  Default is nil.

  :connect-timeout int

  Timeout value, in milliseconds, when opening a connection to the
  URL.  Default is zero, meaning no timeout.

  :read-timeout int

  Timeout value, in milliseconds, when reading data from the
  connection.  Default is zero, meaning no timeout.

  :follow-redirects boolean

  If true, HTTP 3xx redirects will be followed automatically.  Default
  is true.

  :handler f

  Function to be called when the HTTP response body is ready.  If you
  do not provide a handler function, the default is to buffer the
  entire response body in memory.

  The handler function will be called with the HTTP agent as its
  argument, and can use the 'stream' function to read the response
  body.  The return value of this function will be stored in the state
  of the agent and can be retrieved with the 'result' function.  Any
  exceptions thrown by this function will be added to the agent's
  error queue (see agent-errors).  The default function collects the
  response stream in a memory buffer.
  "
  ([uri & options]
     (let [opts (merge *http-agent-defaults* (apply array-map options))]
       (let [a (agent {::connection (c/http-connection uri)
                       ::state ::created
                       ::uri uri
                       ::options opts})]
         (send-off a start-request opts)
         (send-off a open-response opts)
         (send-off a handle-response (partial (:handler opts) a) opts)
         (send-off a disconnect opts)))))
Vars in clojure.contrib.http.agent/http-agent: defn let partial send-off
Used in 0 other vars

Comments top

No comments for http-agent. Log in to add a comment.