Add kernel modules and basic kernel handling
This commit is contained in:
@@ -50,6 +50,10 @@ export class HTTPCookieJar {
|
||||
}
|
||||
}
|
||||
|
||||
has(name: string) {
|
||||
return !!this.parsed[name]
|
||||
}
|
||||
|
||||
clear(name: string, options?: HTTPCookieOptions) {
|
||||
if ( !options ) options = {}
|
||||
options.expires = new Date(0)
|
||||
@@ -68,7 +72,9 @@ export class HTTPCookieJar {
|
||||
|
||||
for ( const key in this.parsed ) {
|
||||
if ( !this.parsed.hasOwnProperty(key) ) continue
|
||||
|
||||
const cookie = this.parsed[key]
|
||||
if ( cookie.exists ) continue
|
||||
|
||||
const parts = []
|
||||
parts.push(`${key}=${encodeURIComponent(cookie.originalValue)}`)
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import {HTTPKernelModule} from "../HTTPKernelModule";
|
||||
import {Request} from "../../lifecycle/Request";
|
||||
import {Injectable} from "@extollo/di"
|
||||
import {HTTPKernel} from "../HTTPKernel";
|
||||
|
||||
export class PrepareRequestHTTPModule extends HTTPKernelModule {
|
||||
@Injectable()
|
||||
export class PoweredByHeaderInjectionHTTPModule extends HTTPKernelModule {
|
||||
public static register(kernel: HTTPKernel) {
|
||||
kernel.register(this).first()
|
||||
kernel.register(this).after()
|
||||
}
|
||||
|
||||
public async apply(request: Request) {
|
||||
await request.prepare()
|
||||
// FIXME make this configurable
|
||||
request.response.setHeader('X-Powered-By', 'Extollo')
|
||||
return request
|
||||
}
|
||||
}
|
||||
26
src/http/kernel/module/SetSessionCookieHTTPModule.ts
Normal file
26
src/http/kernel/module/SetSessionCookieHTTPModule.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {HTTPKernelModule} from "../HTTPKernelModule";
|
||||
import {Injectable, Inject} from "@extollo/di";
|
||||
import {uuid_v4} from "@extollo/util";
|
||||
import {HTTPKernel} from "../HTTPKernel";
|
||||
import {Request} from "../../lifecycle/Request";
|
||||
import {Logging} from "../../../service/Logging";
|
||||
|
||||
@Injectable()
|
||||
export class SetSessionCookieHTTPModule extends HTTPKernelModule {
|
||||
@Inject()
|
||||
protected readonly logging!: Logging
|
||||
|
||||
public static register(kernel: HTTPKernel) {
|
||||
kernel.register(this).first() // TODO make this before inject session?
|
||||
}
|
||||
|
||||
public async apply(request: Request) {
|
||||
if ( !request.cookies.has('extollo.session') ) {
|
||||
const session = `${uuid_v4()}-${uuid_v4()}`
|
||||
|
||||
this.logging.verbose(`Starting session: ${session}`)
|
||||
request.cookies.set('extollo.session', session) // FIXME allow configuring this
|
||||
}
|
||||
return request
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user