Skip to content

Commit

Permalink
fix(protocol): Allow https (#13)
Browse files Browse the repository at this point in the history
* allow https

* allow https

* Update envoy-request-params-refiner.test.ts

* Update envoy-fetch.test.ts

* Update envoy-request-params-refiner.test.ts
  • Loading branch information
winguse committed Jan 30, 2018
1 parent c70c8d5 commit ed45d92
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/envoy-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default async function envoyFetch(

const callDirectly = envoyParams.context.shouldCallWithoutEnvoy(host);

if (protocol !== "http:" && !callDirectly) {
throw new Error(`envoy fetch is designed only for http for now, current found: ${url}`);
if (protocol !== "http:" && protocol !== "https:" && !callDirectly) {
throw new Error(`envoy fetch is designed only for http / https for now, current found: ${url}`);
}
const refinedInit: RequestInit = { ...init };

Expand Down
4 changes: 2 additions & 2 deletions src/envoy-request-params-refiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default function envoyRequestParamsRefiner(

const callDirectly = envoyParams.context.shouldCallWithoutEnvoy(host);

if (protocol !== "http:") {
throw new Error(`envoy request is designed only for http for now, current found: ${protocol}`);
if (protocol !== "http:" && protocol !== "https:") {
throw new Error(`envoy request is designed only for http / https for now, current found: ${protocol}`);
}

const oldHeaders: HttpHeader = {};
Expand Down
10 changes: 0 additions & 10 deletions test/envoy-fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,4 @@ describe("envoy-fetch test", () => {
expect(e.message).toBe("Cannot read the URL for envoy to fetch");
});
});

it("should throw Error for http url", () => {
expect.assertions(1);
const param = new EnvoyHttpRequestParams(new EnvoyContext({}));
envoyFetch(param, "https://foo/bar").catch((e: Error) => {
expect(e.message).toBe(
"envoy fetch is designed only for http for now, current found: https://foo/bar"
);
});
});
});
6 changes: 0 additions & 6 deletions test/envoy-request-params-refiner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ describe("Envoy request params refiner test", () => {
expect(() => {
envoyRequestParamsRefiner("invalid url", {});
}).toThrow();
expect(() => {
envoyRequestParamsRefiner("https://foo.bar/path", {});
}).toThrow();
expect(() => {
envoyRequestParamsRefiner(
{
Expand All @@ -22,9 +19,6 @@ describe("Envoy request params refiner test", () => {
expect(() => {
envoyRequestParamsRefiner({ url: "invalid url" }, {});
}).toThrow();
expect(() => {
envoyRequestParamsRefiner({ url: "https://foo.bar/path" }, new EnvoyContext({}));
}).toThrow();
});

it("should refine the params (string url)", () => {
Expand Down

0 comments on commit ed45d92

Please sign in to comment.