Skip to content
Snippets Groups Projects
Commit 9dbd2eec authored by lotte's avatar lotte
Browse files

moved fix to request service

parent 57cd1772
No related branches found
No related tags found
No related merge requests found
......@@ -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;
})
);
}
......
......@@ -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')) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment