Skip to content
Snippets Groups Projects
Commit 987e5abc authored by lotte's avatar lotte
Browse files

fixed bug with lazy initialization

parent 1bf239f8
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ import { DSpaceObject } from '../shared/dspace-object.model'; ...@@ -6,7 +6,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
import { RestRequestMethod } from '../data/rest-request-method'; import { RestRequestMethod } from '../data/rest-request-method';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
describe('DSpaceRESTv2Service', () => { fdescribe('DSpaceRESTv2Service', () => {
let dSpaceRESTv2Service: DSpaceRESTv2Service; let dSpaceRESTv2Service: DSpaceRESTv2Service;
let httpMock: HttpTestingController; let httpMock: HttpTestingController;
const url = 'http://www.dspace.org/'; const url = 'http://www.dspace.org/';
...@@ -101,7 +101,8 @@ describe('DSpaceRESTv2Service', () => { ...@@ -101,7 +101,8 @@ describe('DSpaceRESTv2Service', () => {
}); });
it('when a content-type header is provided, it should not use application/json', () => { it('when a content-type header is provided, it should not use application/json', () => {
const headers = new HttpHeaders({'Content-Type': 'text/html'}); let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'text/html');
dSpaceRESTv2Service.request(RestRequestMethod.POST, url, {}, { headers }).subscribe(); dSpaceRESTv2Service.request(RestRequestMethod.POST, url, {}, { headers }).subscribe();
const req = httpMock.expectOne(url); const req = httpMock.expectOne(url);
......
...@@ -8,7 +8,6 @@ import { HttpObserve } from '@angular/common/http/src/client'; ...@@ -8,7 +8,6 @@ import { HttpObserve } from '@angular/common/http/src/client';
import { RestRequestMethod } from '../data/rest-request-method'; import { RestRequestMethod } from '../data/rest-request-method';
import { isNotEmpty } from '../../shared/empty.util'; import { isNotEmpty } from '../../shared/empty.util';
import { DSpaceObject } from '../shared/dspace-object.model'; import { DSpaceObject } from '../shared/dspace-object.model';
import { cloneDeep } from 'lodash';
export interface HttpOptions { export interface HttpOptions {
body?: any; body?: any;
...@@ -41,8 +40,9 @@ export class DSpaceRESTv2Service { ...@@ -41,8 +40,9 @@ export class DSpaceRESTv2Service {
get(absoluteURL: string): Observable<DSpaceRESTV2Response> { get(absoluteURL: string): Observable<DSpaceRESTV2Response> {
const requestOptions = { const requestOptions = {
observe: 'response' as any, observe: 'response' as any,
headers: new HttpHeaders({ 'Content-Type': 'application/json; charset=utf-8' }) headers: new HttpHeaders()
}; };
requestOptions.headers = requestOptions.headers.set( 'Content-Type', 'application/json; charset=utf-8' );
return this.http.get(absoluteURL, requestOptions).pipe( return this.http.get(absoluteURL, requestOptions).pipe(
map((res: HttpResponse<any>) => ({ map((res: HttpResponse<any>) => ({
payload: res.body, payload: res.body,
...@@ -82,27 +82,17 @@ export class DSpaceRESTv2Service { ...@@ -82,27 +82,17 @@ export class DSpaceRESTv2Service {
if (options && options.responseType) { if (options && options.responseType) {
requestOptions.responseType = options.responseType; requestOptions.responseType = options.responseType;
} }
// WORKING OPTION
// requestOptions.headers = ((options && options.headers) || new HttpHeaders()).set('blaat', 'bla').delete('blaat');
// OPTION 1 if (options && options.headers) {
// requestOptions.headers = ((options && options.headers) || new HttpHeaders()); requestOptions.headers = Object.assign(new HttpHeaders(), options.headers);
} else {
requestOptions.headers = new HttpHeaders();
}
// OPTION 2 if (!requestOptions.headers.has('Content-Type')) {
// requestOptions.headers = new HttpHeaders(); // Because HttpHeaders is immutable, the set method returns a new object instead of updating the existing headers
// if (options && options.headers) { requestOptions.headers = requestOptions.headers.set('Content-Type', 'application/json; charset=utf-8');
// options.headers.keys().forEach((key) => { }
// options.headers.getAll(key).forEach((header) => {
// // Because HttpHeaders is immutable, the set method returns a new object instead of updating the existing headers
// requestOptions.headers = requestOptions.headers.set(key, header);
// })
// });
// }
//
// if (!requestOptions.headers.has('Content-Type')) {
// // Because HttpHeaders is immutable, the set method returns a new object instead of updating the existing headers
// requestOptions.headers = requestOptions.headers.set('Content-Type', 'application/json; charset=utf-8');
// }
return this.http.request(method, url, requestOptions).pipe( return this.http.request(method, url, requestOptions).pipe(
map((res) => ({ map((res) => ({
payload: res.body, payload: res.body,
......
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