diff --git a/src/Get.test.tsx b/src/Get.test.tsx
index 63534de2..cae61f82 100644
--- a/src/Get.test.tsx
+++ b/src/Get.test.tsx
@@ -544,6 +544,27 @@ describe("Get", () => {
expect(children.mock.calls[1][1].loading).toEqual(false);
expect(children.mock.calls[1][0]).toEqual({ id: 1 });
});
+
+ it("should add a custom header with requestOptions method", async () => {
+ nock("https://my-awesome-api.fake", { reqheaders: { foo: "bar" } })
+ .get("/")
+ .reply(200, { id: 1 });
+
+ const children = jest.fn();
+ children.mockReturnValue(
);
+
+ render(
+
+ ({ headers: { foo: "bar" } })}>
+ {children}
+
+ ,
+ );
+
+ await wait(() => expect(children.mock.calls.length).toBe(2));
+ expect(children.mock.calls[1][1].loading).toEqual(false);
+ expect(children.mock.calls[1][0]).toEqual({ id: 1 });
+ });
});
describe("actions", () => {
diff --git a/src/Poll.test.tsx b/src/Poll.test.tsx
index 3ec7f377..856482ad 100644
--- a/src/Poll.test.tsx
+++ b/src/Poll.test.tsx
@@ -657,5 +657,47 @@ describe("Poll", () => {
expect(children.mock.calls[1][1].loading).toEqual(false);
expect(children.mock.calls[1][0]).toEqual({ id: 1 });
});
+
+ it("should add a custom header with requestOptions method", async () => {
+ nock("https://my-awesome-api.fake", { reqheaders: { foo: "bar" } })
+ .get("/")
+ .reply(200, { id: 1 });
+
+ const children = jest.fn();
+ children.mockReturnValue();
+
+ render(
+
+ ({ headers: { foo: "bar" } })}>
+ {children}
+
+ ,
+ );
+
+ await wait(() => expect(children.mock.calls.length).toBe(2));
+ expect(children.mock.calls[1][1].loading).toEqual(false);
+ expect(children.mock.calls[1][0]).toEqual({ id: 1 });
+ });
+
+ it("should merge headers with providers", async () => {
+ nock("https://my-awesome-api.fake", { reqheaders: { foo: "bar", baz: "qux" } })
+ .get("/")
+ .reply(200, { id: 1 });
+
+ const children = jest.fn();
+ children.mockReturnValue();
+
+ render(
+
+ ({ headers: { foo: "bar" } })}>
+ {children}
+
+ ,
+ );
+
+ await wait(() => expect(children.mock.calls.length).toBe(2));
+ expect(children.mock.calls[1][1].loading).toEqual(false);
+ expect(children.mock.calls[1][0]).toEqual({ id: 1 });
+ });
});
});
diff --git a/src/Poll.tsx b/src/Poll.tsx
index 6bec59a5..921b2a87 100644
--- a/src/Poll.tsx
+++ b/src/Poll.tsx
@@ -1,3 +1,4 @@
+import merge from "lodash/merge";
import * as qs from "qs";
import * as React from "react";
import equal from "react-fast-compare";
@@ -339,16 +340,22 @@ function Poll(
// Compose Contexts to allow for URL nesting
return (
- {contextProps => (
-
- )}
+ {contextProps => {
+ const contextRequestOptions =
+ typeof contextProps.requestOptions === "function"
+ ? contextProps.requestOptions()
+ : contextProps.requestOptions || {};
+ const propsRequestOptions =
+ typeof props.requestOptions === "function" ? props.requestOptions() : props.requestOptions || {};
+
+ return (
+
+ );
+ }}
);
}