Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
42
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
code.vt.edu will be down for maintenance from 0530-0630 EDT Wednesday, March 26th
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
987e5abc
Commit
987e5abc
authored
5 years ago
by
lotte
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug with lazy initialization
parent
1bf239f8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts
+3
-2
3 additions, 2 deletions
src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts
src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts
+11
-21
11 additions, 21 deletions
src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts
with
14 additions
and
23 deletions
src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts
+
3
−
2
View file @
987e5abc
...
...
@@ -6,7 +6,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
import
{
RestRequestMethod
}
from
'
../data/rest-request-method
'
;
import
{
HttpHeaders
}
from
'
@angular/common/http
'
;
describe
(
'
DSpaceRESTv2Service
'
,
()
=>
{
f
describe
(
'
DSpaceRESTv2Service
'
,
()
=>
{
let
dSpaceRESTv2Service
:
DSpaceRESTv2Service
;
let
httpMock
:
HttpTestingController
;
const
url
=
'
http://www.dspace.org/
'
;
...
...
@@ -101,7 +101,8 @@ describe('DSpaceRESTv2Service', () => {
});
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
();
const
req
=
httpMock
.
expectOne
(
url
);
...
...
This diff is collapsed.
Click to expand it.
src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts
+
11
−
21
View file @
987e5abc
...
...
@@ -8,7 +8,6 @@ import { HttpObserve } from '@angular/common/http/src/client';
import
{
RestRequestMethod
}
from
'
../data/rest-request-method
'
;
import
{
isNotEmpty
}
from
'
../../shared/empty.util
'
;
import
{
DSpaceObject
}
from
'
../shared/dspace-object.model
'
;
import
{
cloneDeep
}
from
'
lodash
'
;
export
interface
HttpOptions
{
body
?:
any
;
...
...
@@ -41,8 +40,9 @@ export class DSpaceRESTv2Service {
get
(
absoluteURL
:
string
):
Observable
<
DSpaceRESTV2Response
>
{
const
requestOptions
=
{
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
(
map
((
res
:
HttpResponse
<
any
>
)
=>
({
payload
:
res
.
body
,
...
...
@@ -82,27 +82,17 @@ export class DSpaceRESTv2Service {
if
(
options
&&
options
.
responseType
)
{
requestOptions
.
responseType
=
options
.
responseType
;
}
// WORKING OPTION
// requestOptions.headers = ((options && options.headers) || new HttpHeaders()).set('blaat', 'bla').delete('blaat');
// OPTION 1
// requestOptions.headers = ((options && options.headers) || new HttpHeaders());
if
(
options
&&
options
.
headers
)
{
requestOptions
.
headers
=
Object
.
assign
(
new
HttpHeaders
(),
options
.
headers
);
}
else
{
requestOptions
.
headers
=
new
HttpHeaders
();
}
// OPTION 2
// requestOptions.headers = new HttpHeaders();
// if (options && options.headers) {
// 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');
// }
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
(
map
((
res
)
=>
({
payload
:
res
.
body
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment