Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
2995fed2
Commit
2995fed2
authored
Sep 05, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix format guessing: extension check preempts headers
parent
298fc126
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
12 deletions
+28
-12
globalUtils.js
twmain/globalUtils.js
+28
-12
No files found.
twmain/globalUtils.js
View file @
2995fed2
...
...
@@ -13,11 +13,25 @@ var AjaxSync = function(args) {
if
(
isUndef
(
args
.
datatype
))
args
.
datatype
=
'text'
else
if
(
args
.
datatype
==
"jsonp"
)
args
.
datatype
=
"json"
// will contain success bool, format and data itself
var
Result
=
[]
// format will influence downstream parser choice
var
format
=
null
;
if
(
TW
.
conf
.
debug
.
logFetchers
)
console
.
log
(
"---AjaxSync---"
,
args
)
// use file extension to guess expected format (headers are more variable)
if
(
args
.
url
&&
args
.
url
.
length
)
{
let
extMatch
=
args
.
url
.
match
(
/
\.(
gexf|json
)
$/
)
if
(
extMatch
)
{
format
=
extMatch
.
pop
()
if
(
TW
.
conf
.
debug
.
logFetchers
)
console
.
info
(
`before AjaxSync(
${
args
.
url
}
): format is
${
format
}
, according to file extension`
);
}
}
$
.
ajax
({
type
:
args
.
type
,
url
:
args
.
url
,
...
...
@@ -28,25 +42,27 @@ var AjaxSync = function(args) {
data
:
args
.
data
,
contentType
:
'application/json'
,
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
// header checked iff format not apparent from extension
if
(
format
==
null
)
{
var
header
=
jqXHR
.
getResponseHeader
(
"Content-Type"
)
var
format
;
if
(
!
header
||
header
==
"application/octet-stream"
||
header
==
"application/xml"
)
{
if
(
header
&&
(
header
==
"application/json"
||
header
==
"text/json"
)
)
{
format
=
"json"
;
}
else
{
// default parser choice if xml or if undetailed header
format
=
"gexf"
;
}
else
{
if
(
TW
.
conf
.
debug
.
logFetchers
)
console
.
debug
(
"after AjaxSync("
+
args
.
url
+
") => response header="
+
header
+
"not xml => fallback on json"
);
format
=
"json"
;
console
.
debug
(
"after AjaxSync("
+
args
.
url
+
") => response header="
+
header
+
"not json => fallback on xml gexf"
);
}
Result
=
{
"OK"
:
true
,
"format"
:
format
,
"data"
:
data
};
}
Result
=
{
"OK"
:
true
,
"format"
:
format
,
"data"
:
data
};
},
error
:
function
(
exception
)
{
console
.
warn
(
'ajax error:'
,
exception
,
exception
.
getAllResponseHeaders
())
Result
=
{
"OK"
:
false
,
"format"
:
false
,
"data"
:
exception
.
status
};
console
.
warn
(
'ajax error:'
,
exception
,
exception
.
getAllResponseHeaders
())
Result
=
{
"OK"
:
false
,
"format"
:
false
,
"data"
:
exception
.
status
};
}
});
return
Result
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment