diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts index fd463047f121a375203aa88f5ea4d3cd35f63fb2..9f79d7539bff8bbeb3c91eb2dee26f175c7f7897 100644 --- a/src/app/core/data/request.service.ts +++ b/src/app/core/data/request.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store'; import { Observable, race as observableRace } from 'rxjs'; -import { filter, mergeMap, take } from 'rxjs/operators'; +import { filter, map, mergeMap, take } from 'rxjs/operators'; import { AppState } from '../../app.reducer'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; @@ -23,6 +23,8 @@ import { CommitSSBAction } from '../cache/server-sync-buffer.actions'; import { RestRequestMethod } from './rest-request-method'; import { AddToIndexAction, RemoveFromIndexBySubstringAction } from '../index/index.actions'; import { coreSelector } from '../core.selectors'; +import { HttpHeaders } from '@angular/common/http'; +import { cloneDeep } from 'lodash'; /** * The base selector function to select the request state in the store @@ -118,6 +120,16 @@ export class RequestService { return this.store.pipe(select(entryFromUUIDSelector(originalUUID))) }, )) + ).pipe( + map((entry: RequestEntry) => { + // Headers break after being retrieved from the store (because of lazy initialization) + // Combining them with a new object fixes this issue + if (hasValue(entry) && hasValue(entry.request) && hasValue(entry.request.options) && hasValue(entry.request.options.headers)) { + entry = cloneDeep(entry); + entry.request.options.headers = Object.assign(new HttpHeaders(), entry.request.options.headers) + } + return entry; + }) ); } diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts index 84d4d559b8a8e591f49eb9e5b96143c2515716c9..204c782e796756b877bc8e48559bca7274dcf965 100644 --- a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts @@ -6,7 +6,7 @@ import { HttpClient, HttpHeaders, HttpParams, HttpResponse } from '@angular/comm import { DSpaceRESTV2Response } from './dspace-rest-v2-response.model'; import { HttpObserve } from '@angular/common/http/src/client'; import { RestRequestMethod } from '../data/rest-request-method'; -import { isNotEmpty } from '../../shared/empty.util'; +import { hasNoValue, isNotEmpty } from '../../shared/empty.util'; import { DSpaceObject } from '../shared/dspace-object.model'; export const DEFAULT_CONTENT_TYPE = 'application/json; charset=utf-8'; @@ -83,10 +83,10 @@ export class DSpaceRESTv2Service { requestOptions.responseType = options.responseType; } - if (options && options.headers) { - requestOptions.headers = Object.assign(new HttpHeaders(), options.headers); - } else { + if (hasNoValue(options) || hasNoValue(options.headers)) { requestOptions.headers = new HttpHeaders(); + } else { + requestOptions.headers = options.headers; } if (!requestOptions.headers.has('Content-Type')) {