Commit graph

83 commits

Author SHA1 Message Date
Andrew Roetker
40d2cfb3c3 (PE-18703) Pass negotiated locale in Accept-Language header
This commit passes the negotiated locale via the i18n/*locale* variable
through the Accept-Language header by default in a clj-http-client
request (only in the Clojure client, not the Java client).
2016-12-05 11:37:40 -08:00
Ruth Linehan
4f92c1ba55 (TK-402) Allow metric namespace to be configurable
Add two new client options - `server-id` and `metric-prefix` that allow the
metric namespace to be configured rather than always
`puppetlabs.http-client.experimental`.

If `server-id` is set, the metric namespace becomes
`puppetlabs.<server-id>.http-client.experimental`.

If `metric-prefix` is set, the metric namespace becomes
`<metric-prefix>.http-client.experimental`.

If both are set, `metric-prefix` wins out and a warning message is logged.

Also add a `get-client-metric-namespace`/`getMetricNamespace` method on the
client (clojure and java) to get back the metric namespace.
2016-10-03 12:06:15 -07:00
janelu2
23b44ae93d (TK-295) add tests for cookies
(MAINT) remove comments

(MAINT) change body message to reflect 400 status

(MAINT) change test to use Java and Clj API

(MAINT) refactor RequestOptions in let block of java api test

(MAINT) add tests for async cookie support
2016-07-19 14:27:02 -07:00
Ruth Linehan
d3325c494e (TK-316) Add back accidentally deleted test 2016-05-05 09:36:56 -07:00
Chris Price
6ec92839c1 (TK-316) More explicit methods for timer/data lists 2016-05-05 04:48:07 -07:00
Ruth Linehan
e403b2abc8 (TK-316) Add public url conversion method
When constructing url timers for request metrics, we strip off any username,
password, query params, and path fragments on the request uri. This commit
provides a public method to do this conversion of a url, so that users can
take the url they used for their request and easily figure out the url we used
for the metric.
2016-05-04 16:25:52 -07:00
Chris Price
f43594eddb (TK-316) Move private Metrics methods to impl class 2016-05-04 15:52:00 -07:00
Chris Price
e8a4ff4707 (TK-316) Move Java classes to separate metrics namespaces 2016-05-04 15:25:58 -07:00
Ruth Linehan
2e99e8a08c (TK-316) Throw error if no metric registry passed into get-client-metrics* fns
Previously, if any of the `get-client-metrics*` methods (in Clojure or Java)
had a nil metric registry passed into them, they would return nil. This commit
updates the behavior of all of these methods to instead return an error - a
schema error (clojure.lang.ExceptionInfo) for the clojure functions, and an
IllegalArgumentException for the java methods.
2016-05-04 15:10:24 -07:00
Ruth Linehan
da4d59fb7d (TK-316) Remove second arity of get-client-metrics* functions
Previously, all the get-client-metrics* functions had two arities - one with a
metric type and one without. This commit removes the arity with a metric type
from all these functions since currently we only have one metric type and
since we aren't entirely certain of what we want the API to be when we add
additional metric types. When we add more metric types, we will change the API
in a backward compatible way.
2016-05-04 10:38:41 -07:00
Ruth Linehan
43cdd07580 (TK-316) Add specific schemas for different categories of metrics data
Rather than having e.g a nil url and method in the metric data when metric-id
is filtered on, or a nil metric id if url and method are filtered on, use
specific schemas for metrics data returned for each metric category - metric
id, url, and url and method.
2016-05-04 10:07:48 -07:00
Ruth Linehan
55d565acd7 (TK-316) Rename bytes-read to full-response
Rename the Metric Types from `bytes-read`/`init-repsonse` to
`full-response`/`initial-response` (note that the `initial-response` timer has
not yet been implemented, but when it is this will be its name).
2016-04-22 15:08:52 -07:00
Ruth Linehan
b744e99749 (TK-316) Improve metrics API
This commit does several things to improve the metrics API:

* Move get-client-metrics(-data) functions off of client:
Previously, the `get-client-metrics(-data)`/`.getClientMetrics(Data)`
functions were on the client. This didn't entirely make sense because if two
clients were using the same metric registry, these functions would actually
return metrics data for *all* clients, rather than just for the client the
function was called on. This commit removes these functions and changes the
tests to use the metrics namepsace/Metrics class versions instead, which take
a metric registry return all http-client related metrics on that metric
registry.

* Add a `with-url-and-method` namespace:
Move the timers that have both the url and the method from the `with-url`
namespace to a new `with-url-and-method` namepsace. This better matches the
data structure are returned in and the filtering mechanisms for getting them
back out (discussed below), and also removes a slight chance of having a
conflict with a url timer.

* Add a ClientTimer class:
Add a ClientTimer class that wraps the Timer class and also holds onto the
url, method, or metric id used to create the timer. Use this to add url,
method, metricId to ClientMetricData.

* Change the `getClientMetrics(Data)` methods to return a map of metric
category to an array of timers or timer data:
Previously, the methods for getting http client metrics/metric data out of a
metric registry returned a map of metric name to timer instance or metric
data. However, the metric name was most likely not useful to users, who
probably just want to iterate through the timers/data. This commit makes the
output of these functions more useful by returning arrays of timers/data
sorted into a map indexed by metric category (url, url and method, or metric
id).

* Add `getClientMetricsBy*` methods:
Add `getClientMetrics(Data)ByUrl`, `getClientMetrics(Data)ByUrlAndMethod`, and
`getClientMetrics(Data)ByMetricId` methods (and clojure versions) that allow
for filtering by a specific metric category and return an array of timers or
timer data that match the url, url and method, or metric id specified.

* Remove the filter-builder functions:
Previously, the `get-client-metrics(-data)` functions did filtering by taking
a filter map, and there were filter-builder functions to build these filter
maps. Now that there are separate filtering methods, these filter maps are no
longer used and the filter-builder functions are removed.
2016-04-19 13:13:10 -07:00
Ruth Linehan
df4e36a1aa (TK-316) Add metrics support
This commit adds metrics support to the http client (clojure and java, sync
and async). A metric registry can optionally be passed into the client as a
client option on creation. If a metric registry is present, timers will be
added to time each request.

By default, a timer is added for the URL (stripped of username, password,
query string, and path fragments) and the URL plus the method used for the
request. In addition, a request can include a `metric-id` option, which takes
a tuple of metric ids. If this request option is specified, a timer will be
created for each element of the metric id tuple - thus if the tuple is [:foo
:bar :baz] there will be a foo timer, a foo.bar timer, and a foo.bar.baz
timer.

In addition, each timer has a "MetricType" - currently there is only one
metric type, bytes-read, which is stopped when the full response has been
read. In the future, we may add "response-init" timers that get stopped when
the first byte of the response has been read.

This commit also adds a `get-client-metrics`/`.getClientMetrics` function that
takes a client instance and returns the http client-specific metrics from the
metric registry and a `get-client-metrics-data`/`.getClientMetricsData`
function for clojure and java sync and async clients to get out metrics data
from the client. This function takes a client instance and returns a map of
metric name to a map of metric data (for clojure) or a ClientMetricData object
(for java), both of which include the mean, count, and aggregate for the timer

These `get-client-metrics*`/`.getClientMetrics*` functions also have versions
that take a url, url and method, or metric id to allow for filtering of the
timers/metrics data returned by these functions.

The clojure versions of these functions take a metric filter map. There are
also metric filter builder functions to build up the type of metric filter
desired from a url, a url and method, or a metric id. These will prevent users
from having to know the specifics of how to build a metric themselves; instead
they can use a convenience function.

An empty metric id can be passed in to the filter to return all metric-id
timers.
2016-04-19 13:13:10 -07:00
Ruth Linehan
4176251521 (TK-179) Remove unused ssl config functions
These functions were previously used for initializing an ssl context for the
clojure http client. However, with the clojure client initialization now just
wrapping the java code, these are no longer needed.
2016-02-08 14:00:07 +00:00
Scott Walker
66c584fff4 Handle an empty content type in the response 2016-02-04 13:11:27 +00:00
Scott Walker
41836a72ad Add async/sync test to check that a bad HTTP verb is rejected 2016-02-04 11:07:07 +00:00
Scott Walker
8548bbb4d7 (TK-179) Modify the Clojure implementation to share more of the Java impl
This commit removes duplicate functionality from the Clojure implementation and reuses the Java request/response handling impl. It doesn't address client creation so there are still two distinct paths for that.

The main changes are Ring <-> Java request/response conversion and the addition of interface ResponseDeliveryDelegate. The delegate implementations take care of the language-specific aspects of response building and promise delivery. One of the Clojure test namespaces is removed too.
2016-02-04 10:47:18 +00:00
Alex Dreyer
a383bd7046 Add a general request function to the client protocol.
There are a few places where we map request method keywords to
http-client function. The http client then maps them back to keywords
which is redundant. This adds a general request function to the protocol
that accepts a keyword method.
2016-01-29 08:45:44 -08:00
Scott Walker
15b13fed4f Update Java API to include ResponseBodyType.UNBUFFERED_STREAM and update Clojure implementation to give consistent HttpContext usage with both clj and Java 2016-01-15 14:31:36 +00:00
Scott Walker
a5ed1d0bf8 Move unbuffered stream Clojure tests into a separate namespace 2016-01-11 07:57:12 +00:00
Chris Price
e7c9d22aa4 (MAINT) Update to latest apache httpasyncclient
This commit updates us to the latest version of the Apache
HTTPAsyncClient.  This is necessary in order to make it
possible to use this library in the same VM as the latest
version of clj-http, because they have some common dependencies.

The commit also cleans up some other dependencies while I was
in there.
2015-12-18 12:21:27 -08:00
Scott Walker
fbab9a37bc Rework tests for improved clarity and AsyncConsumer releaseResources() fix 2015-10-13 12:09:50 +01:00
Scott Walker
862090251c Incorporate comments from camlow325
- Fixes to ExceptionInsertingPipedInputStream
- Fix to async consumer and removal of decompression code
- Use ResponseContentEncoding to do all decompression including removing previous approach
- Clarify tests and add ConnectionException
2015-10-07 17:45:18 +01:00
Scott Walker
ca5ad63179 (PE-11976) Add option to return the response early and stream the body asynchronously
Adds a new :as option that uses Apache's AsyncConsumer to return the response as quickly as possible then asynchronously stream the response body using piped input/output streams.
2015-10-05 15:38:30 +01:00
Joe Pinsonault
c5489e0e43 (MAINT) Added fix/test for java coerceBodyType 2015-04-24 10:17:30 -07:00
Joe Pinsonault
08ca923e69 (MAINT) nil body is coerced into empty string 2015-04-24 10:17:05 -07:00
Joe Pinsonault
c906d5abd0 (TK-182) coerce-body-type handles nil body 2015-04-24 10:05:29 -07:00
Jeremy Barlow
a4c8994189 (MAINT) Fix timeout test names and testing strings
This commit has a couple of cosmetic fixes to the names and testing
strings for a few tests introduced by TK-134.
2015-03-19 21:25:55 -07:00
Jeremy Barlow
6520abfb1d (TK-134) Updated connection tests to handle Connect or SocketTimeout
This commit updates the short connect timeout tests to tolerate either a
ConnectException or SocketTimeoutException as a success condition.
Connections could fail with either exception depending upon timing or
network setup.
2015-03-16 22:46:07 -07:00
Jeremy Barlow
9b55ed31b6 (TK-134) Add connect and socket timeout client configuration
This commit enables http clients to optionally configure a connect
and/or socket timeout for requests.  For persistent clients, the
timeout values can only be configured at the client and not a
per-request level.  Non-persistent client requests support the
configuration of these timeouts.

This commit also bumps a few dependencies - tk-jetty9 to 1.2.0,
trapperkeeper to 1.10, ssl-utils to 0.8.0, and clojure to 1.6.0 -
and adds the 'test' tk-jetty9 library as a dev dependency for
testing.
2015-03-16 12:22:35 -07:00
Kevin Corcoran
95a88286ce (TK-145) fix default charset in Java client
Fix a bug in which a default charset of UTF-8 would be added to the
Content-Type header for certain requests.  This change restricts that
behavior to cases in which the body is a string and there is no charset
provided by the caller.
2015-02-13 11:32:04 -08:00
Kevin Corcoran
583b71a556 (TK-145) fix application of default charset
Fix a bug in which a default charset of UTF-8 would be added to the
Content-Type header for certain requests.  This change restricts that
behavior to cases in which the body is a string and there is no charset
provided by the caller.
2015-02-13 10:53:12 -08:00
Nate Wolfe
e164bb12d7 (SERVER-101) Upgrade jvm-ca dependency to 0.7.0
This commit changes the usages to reflect the new name of the library
and API.
2015-01-23 17:33:02 -08:00
Jeremy Barlow
137ae4bd48 (TK-103) Restored redirect-test-async tests
This commit restores several of the `rediret-test-async` tests, using a
client to make the requests since the client-less single-request async
APIs are no longer available.
2014-11-15 14:37:00 -08:00
Jeremy Barlow
91f679a795 (TK-103) Restored query-params-test-async tests
This commit restores the `query-params-test-async` tests, using a client
to make the requests since the client-less single-request async APIs are
no longer available.
2014-11-14 15:54:02 -08:00
Jeremy Barlow
4e56352c44 (TK-103) Restore client close tests
This commit restores some of the client close tests which had been
disabled temporarily per some of the refactoring for TK-108.
2014-11-12 14:20:50 -08:00
Jeremy Barlow
c1abea3e37 (TK-103) Remove AsyncClose class and references
This commit removes the `AsyncClose` class and references to it.  These
changes are in preparation for making the close call after the response
has been dereferenced - to be done in a later commit.  The `persistent`
flag/option was also removed from request handling as it will no longer
be used for determining whether or not the client should be closed
following a request.
2014-11-12 11:37:44 -08:00
Jeremy Barlow
d437646203 (TK-103) Remove non-client based async APIs
This commit removes the non-client based APIs for doing async requests.
2014-11-12 11:04:11 -08:00
Preben Ingvaldsen
c77e449f11 (TK-108) Remove failing close test
Remove the tests to ensure that the persistent async and sync
Java clients close correctly due to a race condition that
was present in the tests.
2014-11-11 09:45:18 -08:00
Preben Ingvaldsen
fb6772b623 (TK-108) Return interface in createClient methods
Return interfaces in the createClient methods rather than the
implementation classes themselves.
2014-11-10 11:24:36 -08:00
Preben Ingvaldsen
8126f13100 (TK-108) Add SimpleRequestOptions class
Add SimpleRequestOptions class, which unifies the Client and
Request options under a single class used for the simple API
calls.
2014-11-10 11:05:15 -08:00
Preben Ingvaldsen
c6ce8dd301 (TK-108) Add a persistent sync Java client
Add a PersistentSyncHttpClient class, which is a wrapper around
CloseableHttpAsyncClient and allows multiple requests to be made
with a persistent synchronous client.
2014-11-10 10:08:13 -08:00
Preben Ingvaldsen
018fe70153 (TK-108) Add a persistent async Java client
Add a new class, PersistentAsyncHttpClient, that is a wrapped
CloseableHttpAsyncClient that is persistent.
2014-11-07 13:29:17 -08:00
Preben Ingvaldsen
972de1e9e9 (TK-108) Separate Java RequestOptions class
Separate the Java RequestOptions class into two new classes:
RequestOptions, which contains options related to the request,
and ClientOptions, which contains options related to the client.
Both are now required when calling the request methods in
AsyncHttpClient and SyncHttpClient.
2014-11-07 10:44:20 -08:00
Kevin Corcoran
fa852c9b7c Merge pull request #21 from camlow325/bug/master/TK-101-clients-leaked-on-fail
(TK-101) Move closing of http clients to a separate thread
2014-10-21 15:36:35 -07:00
Chris Price
b70ac50b17 (TK-97) Fix bug in tests on Oracle JDKs
The test code related to the configurable SSL protocols was
written using some ciphers that are available in OpenJDK, but
are not available by default in Oracle JDK.  This caused the
tests to fail on Oracle JDKs.

This commit changes the test to use some older ciphers that
are available in the Oracle JDK out of the box.
2014-10-21 15:08:15 -07:00
Jeremy Barlow
f859bd907a (TK-101) Move closing of http clients to a separate thread
This commit moves each close call made on a `CloseableHttpAsyncClient`
from the thread on which the request callback is made over to a
different thread in order to avoid a deadlock.

Previously, the client close call was made in the context of thread from
which the callback was invoked.  The Apache HTTP async client library
makes these calls from one of its i/o reactor threads.  In the case of a
"failed" request, e.g., failure to make the client connection, this call
occurs in the context of the primary i/o reactor thread.  The client
close call does an indefinite join on the primary i/o reactor thread
and, therefore, this call causes a deadlock.  The client never closes
and all resources associated with it - threads, file descriptors, etc. -
remain open until the process is shutdown.

This commit introduces a new class, `AsyncClose`, which manages a small,
fixed size thread pool from which client close calls can be executed.
The `async` Clojure and `JavaClient` APIs were updated to use `AsyncClose`
whenever a client needs to be closed from a callback.
2014-10-20 14:22:56 -07:00
Chris Price
251d859d10 (TK-97) Expose configuration settings for protocols/cipher suites
This commit adds configuration settings for the SSL protocols
and cipher suites, in both the java and clojure clients.  It
also adds a list of default protocols which will be used if
the protocols setting is not explicitly set.
2014-10-17 23:35:05 -07:00
Chris Price
c2cbb11d5d (TK-97) Update dependencies to latest versions
Update dependencies (trapperkeeper, trapperkeeper-webserver-jetty9,
etc.) to the latest versions and fix tests accordingly.
2014-10-17 19:50:08 -07:00