From 622aca9066db65592f01d3bd49ef903f2d14846c Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Fri, 22 Jul 2022 17:52:22 +0200 Subject: [PATCH] fix saneurl --- docs/releases/v2.7.3.md | 1 + e2e/checklist.md | 3 +++ src/share/saneUrl/saneUrl.service.ts | 13 +++++++++---- src/util/priority.ts | 9 +++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/releases/v2.7.3.md b/docs/releases/v2.7.3.md index 9758f42e5..c87171421 100644 --- a/docs/releases/v2.7.3.md +++ b/docs/releases/v2.7.3.md @@ -3,6 +3,7 @@ ## Bugfix - fixed matomo visitor counting (broke since 2.7.0 release) +- fixed sane url generation ## Under the hood diff --git a/e2e/checklist.md b/e2e/checklist.md index eef89d804..d03d59b1f 100644 --- a/e2e/checklist.md +++ b/e2e/checklist.md @@ -65,6 +65,9 @@ - [ ] on hover, show correct region name(s) - [ ] whole mesh loads ## saneURL +- [ ] saneurl generation functions properly + - [ ] try existing key (human), and get unavailable error + - [ ] try non existing key, and get available - [ ] [saneUrl](https://atlases.ebrains.eu/viewer-staging/saneUrl/bigbrainGreyWhite) redirects to big brain - [ ] [saneUrl](https://atlases.ebrains.eu/viewer-staging/saneUrl/julichbrain) redirects to julich brain (colin 27) - [ ] [saneUrl](https://atlases.ebrains.eu/viewer-staging/saneUrl/whs4) redirects to waxholm v4 diff --git a/src/share/saneUrl/saneUrl.service.ts b/src/share/saneUrl/saneUrl.service.ts index 8f3af1f3d..c5d9849f7 100644 --- a/src/share/saneUrl/saneUrl.service.ts +++ b/src/share/saneUrl/saneUrl.service.ts @@ -4,23 +4,27 @@ import { throwError } from "rxjs"; import { catchError, mapTo } from "rxjs/operators"; import { BACKENDURL } from 'src/util/constants' import { IKeyValStore, NotFoundError } from '../type' +import { DISABLE_PRIORITY_HEADER } from "src/util/priority" @Injectable({ providedIn: 'root' }) export class SaneUrlSvc implements IKeyValStore{ - public saneUrlRoot = `${BACKENDURL}saneUrl/` + public saneUrlRoot = `${BACKENDURL}go/` constructor( private http: HttpClient ){ - + if (!BACKENDURL) { + const loc = window.location + this.saneUrlRoot = `${loc.protocol}//${loc.hostname}${!!loc.port ? (':' + loc.port) : ''}${loc.pathname}go/` + } } getKeyVal(key: string) { return this.http.get<Record<string, any>>( `${this.saneUrlRoot}${key}`, - { responseType: 'json' } + { responseType: 'json', headers: { [DISABLE_PRIORITY_HEADER]: '1' } } ).pipe( catchError((err, obs) => { const { status } = err @@ -35,7 +39,8 @@ export class SaneUrlSvc implements IKeyValStore{ setKeyVal(key: string, value: any) { return this.http.post( `${this.saneUrlRoot}${key}`, - value + value, + { headers: { [DISABLE_PRIORITY_HEADER]: '1' } } ).pipe( mapTo(`${this.saneUrlRoot}${key}`) ) diff --git a/src/util/priority.ts b/src/util/priority.ts index ab703f76b..79ef1b043 100644 --- a/src/util/priority.ts +++ b/src/util/priority.ts @@ -24,6 +24,8 @@ type Queue = { next: HttpHandler } +export const DISABLE_PRIORITY_HEADER = 'x-sxplr-disable-priority' + @Injectable({ providedIn: 'root' }) @@ -137,8 +139,11 @@ export class PriorityHttpInterceptor implements HttpInterceptor{ * Since the way in which serialization occurs is via path and query param... * body is not used. */ - if (this.disablePriority || req.method !== 'GET') { - return next.handle(req) + if (this.disablePriority || req.method !== 'GET' || !!req.headers.get(DISABLE_PRIORITY_HEADER)) { + const newReq = req.clone({ + headers: req.headers.delete(DISABLE_PRIORITY_HEADER) + }) + return next.handle(newReq) } const { urlWithParams } = req -- GitLab