Skip to content

Commit

Permalink
fix: relax Flow client content-type check (#8796)
Browse files Browse the repository at this point in the history
  • Loading branch information
haijian-vaadin committed Jul 30, 2020
1 parent 312687d commit 9a67dbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ export class Flow {
${httpRequest.responseText}`));

httpRequest.onload = () => {
if (httpRequest.getResponseHeader('content-type') === 'application/json') {
const contentType = httpRequest.getResponseHeader('content-type');
if (contentType && contentType.indexOf('application/json') !== -1) {
resolve(JSON.parse(httpRequest.responseText));
} else {
httpRequest.onerror();
Expand Down
22 changes: 19 additions & 3 deletions flow-client/src/test/frontend/FlowTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,27 @@ suite("Flow", () => {
const flow = new Flow();

const route = flow.serverSideRoutes[0];
await route.action({pathname: "Foo/Bar.baz"});
await route.action({pathname: "Foo/Bar.baz", search:""});

assert.isDefined($wnd.vaadinPush);
assert.isTrue($wnd.vaadinPush.isStub);
});

test("should not throw error when response header content type has charset", async () => {
stubServerRemoteFunction('foobar-1111112');
mockInitResponse('foobar-1111113', undefined, stubVaadinPushSrc, true);
const flow = new Flow();
const route = flow.serverSideRoutes[0];
await route.action({pathname: "Foo/Bar.baz", search:""});
});

test("should not throw error when response header content type has no charset", async () => {
stubServerRemoteFunction('foobar-1111113');
mockInitResponse('foobar-1111113', undefined, stubVaadinPushSrc);
const flow = new Flow();
const route = flow.serverSideRoutes[0];
await route.action({pathname: "Foo/Bar.baz", search:""});
});
});

function stubServerRemoteFunction(id: string, cancel: boolean = false, routeRegex?: RegExp,
Expand Down Expand Up @@ -624,13 +640,13 @@ function stubServerRemoteFunction(id: string, cancel: boolean = false, routeRege
};
}

function mockInitResponse(appId: string, changes = '[]', pushScript?: string) {
function mockInitResponse(appId: string, changes = '[]', pushScript?: string, withCharset?: boolean) {
// Configure a valid server initialization response
mock.get(/^.*\?v-r=init.*/, (req, res) => {
assert.equal('GET', req.method());
return res
.status(200)
.header("content-type","application/json")
.header("content-type", "application/json" + (withCharset ? ";charset=ISO-8859-1" : ""))
.body(createInitResponse(appId, changes, pushScript));
});
}

0 comments on commit 9a67dbc

Please sign in to comment.