Skip to content

Commit

Permalink
fix(server): fixes issue where OPTIONS requests would return METHOD_N…
Browse files Browse the repository at this point in the history
…OT_ALLOWED
  • Loading branch information
wessberg committed Jan 18, 2019
1 parent 38f9dbe commit 3d6f950
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/server/request-handler/request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Response} from "../i-response";
import {printRequest} from "../../util/request-util/request-util";
import {RequestHandlerOptions} from "./request-handler-options";
import {constants} from "http2";
import {METHOD_NOT_ALLOWED, NOT_FOUND, OK} from "http-status-codes";
import {METHOD_NOT_ALLOWED, OK} from "http-status-codes";
import {RegisteredControllers} from "../../controller/controller/registered-controllers";
import {IStaticController} from "../../controller/static/i-static-controller";

Expand Down Expand Up @@ -67,22 +67,10 @@ export class RequestHandler implements IRequestHandler {
*/
private async handleOptionsRequest (options: RequestHandlerOptions): Promise<Response> {

// Find the first matched controller
for (const controller of this.controllers) {
const match = controller.match(options.request);
if (match != null) {
return {
statusCode: options.request.http2
? constants.HTTP_STATUS_OK
: OK
};
}
}

return {
statusCode: options.request.http2
? constants.HTTP_STATUS_NOT_FOUND
: NOT_FOUND
? constants.HTTP_STATUS_OK
: OK
};
}
}
16 changes: 16 additions & 0 deletions test/server/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,20 @@ test("Will set a 'x-applied-polyfills' header on HTTP2 responses with a HTTP-fri
});

t.true(result.polyfillsHeader != null);
});

test("Accepts OPTIONS requests. #1", async t => {

const result = await sendRequest({
http2: config.http2,
tls: true,
userAgent: ie("11"),
method: "OPTIONS",
host: config.host,
port: config.port,
path: `${constant.endpoint.polyfill}?features=event,custom-event,zone,es.promise.finally,pointer-event|force,systemjs|variant=system,intl|force|locale=en~da`,
acceptEncoding: undefined
});

t.true(result.statusCode === 200);
});

0 comments on commit 3d6f950

Please sign in to comment.