mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
@@ -1,16 +1,18 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { ApiVersionInterceptor } from './api-version.interceptor';
|
||||
import { ApiVersionInterceptor } from './api-version.interceptor'
|
||||
|
||||
describe('ApiVersionInterceptor', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({
|
||||
providers: [
|
||||
ApiVersionInterceptor
|
||||
]
|
||||
}));
|
||||
beforeEach(() =>
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ApiVersionInterceptor],
|
||||
})
|
||||
)
|
||||
|
||||
it('should be created', () => {
|
||||
const interceptor: ApiVersionInterceptor = TestBed.inject(ApiVersionInterceptor);
|
||||
expect(interceptor).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const interceptor: ApiVersionInterceptor = TestBed.inject(
|
||||
ApiVersionInterceptor
|
||||
)
|
||||
expect(interceptor).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,25 +1,27 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable } from '@angular/core'
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
HttpInterceptor,
|
||||
} from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
@Injectable()
|
||||
export class ApiVersionInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor() {}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
intercept(
|
||||
request: HttpRequest<unknown>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<unknown>> {
|
||||
request = request.clone({
|
||||
setHeaders: {
|
||||
'Accept': `application/json; version=${environment.apiVersion}`
|
||||
}
|
||||
})
|
||||
setHeaders: {
|
||||
Accept: `application/json; version=${environment.apiVersion}`,
|
||||
},
|
||||
})
|
||||
|
||||
return next.handle(request);
|
||||
return next.handle(request)
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { CsrfInterceptor } from './csrf.interceptor';
|
||||
import { CsrfInterceptor } from './csrf.interceptor'
|
||||
|
||||
describe('CsrfInterceptor', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({
|
||||
providers: [
|
||||
CsrfInterceptor
|
||||
]
|
||||
}));
|
||||
beforeEach(() =>
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CsrfInterceptor],
|
||||
})
|
||||
)
|
||||
|
||||
it('should be created', () => {
|
||||
const interceptor: CsrfInterceptor = TestBed.inject(CsrfInterceptor);
|
||||
expect(interceptor).toBeTruthy();
|
||||
});
|
||||
});
|
||||
const interceptor: CsrfInterceptor = TestBed.inject(CsrfInterceptor)
|
||||
expect(interceptor).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,35 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable } from '@angular/core'
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { Meta } from '@angular/platform-browser';
|
||||
HttpInterceptor,
|
||||
} from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
import { CookieService } from 'ngx-cookie-service'
|
||||
import { Meta } from '@angular/platform-browser'
|
||||
|
||||
@Injectable()
|
||||
export class CsrfInterceptor implements HttpInterceptor {
|
||||
constructor(private cookieService: CookieService, private meta: Meta) {}
|
||||
|
||||
constructor(private cookieService: CookieService, private meta: Meta) {
|
||||
|
||||
}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
let prefix = ""
|
||||
intercept(
|
||||
request: HttpRequest<unknown>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<unknown>> {
|
||||
let prefix = ''
|
||||
if (this.meta.getTag('name=cookie_prefix')) {
|
||||
prefix = this.meta.getTag('name=cookie_prefix').content
|
||||
}
|
||||
let csrfToken = this.cookieService.get(`${prefix?prefix:''}csrftoken`)
|
||||
let csrfToken = this.cookieService.get(`${prefix ? prefix : ''}csrftoken`)
|
||||
if (csrfToken) {
|
||||
request = request.clone({
|
||||
request = request.clone({
|
||||
setHeaders: {
|
||||
'X-CSRFToken': csrfToken
|
||||
}
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return next.handle(request);
|
||||
return next.handle(request)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user