deno.land / x / opine@2.3.4 / test / units / req.protocol.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120import { opine } from "../../mod.ts";import { superdeno } from "../deps.ts";import { describe, it } from "../utils.ts";
describe("req", function () { describe(".protocol", function () { it("should return the protocol string", function (done) { const app = opine();
app.use(function (req, res) { res.end(req.protocol); });
superdeno(app) .get("/") .expect("http", done); });
describe('when "trust proxy" is enabled', function () { it("should respect X-Forwarded-Proto", function (done) { const app = opine();
app.enable("trust proxy");
app.use(function (req, res) { res.end(req.protocol); });
superdeno(app) .get("/") .set("X-Forwarded-Proto", "https") .expect("https", done); });
it( "should default to the conn addr if X-Forwarded-Proto not present", function ( done, ) { const app = opine();
app.enable("trust proxy");
app.use(function (req, res) { req.proto = "https"; res.end(req.protocol); });
superdeno(app) .get("/") .expect("https", done); }, );
it("should ignore X-Forwarded-Proto if conn addr not trusted", function ( done, ) { const app = opine();
app.set("trust proxy", "10.0.0.1");
app.use(function (req, res) { res.end(req.protocol); });
superdeno(app) .get("/") .set("X-Forwarded-Proto", "https") .expect("http", done); });
it("should default to http", function (done) { const app = opine();
app.enable("trust proxy");
app.use(function (req, res) { res.end(req.protocol); });
superdeno(app) .get("/") .expect("http", done); });
describe("when trusting hop count", function () { it("should respect X-Forwarded-Proto", function (done) { const app = opine();
app.set("trust proxy", 1);
app.use(function (req, res) { res.end(req.protocol); });
superdeno(app) .get("/") .set("X-Forwarded-Proto", "https") .expect("https", done); }); }); });
describe('when "trust proxy" is disabled', function () { it("should ignore X-Forwarded-Proto", function (done) { const app = opine();
app.use(function (req, res) { res.end(req.protocol); });
superdeno(app) .get("/") .set("X-Forwarded-Proto", "https") .expect("http", done); }); }); });});
Version Info