Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scanner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
whats-this
scanner
Commits
2c47d357
Commit
2c47d357
authored
8 years ago
by
aurieh
Browse files
Options
Downloads
Patches
Plain Diff
Fix body parser
parent
5eac844a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.js
+24
-21
24 additions, 21 deletions
index.js
with
24 additions
and
21 deletions
index.js
+
24
−
21
View file @
2c47d357
...
@@ -46,34 +46,37 @@ app.use(function* (next) {
...
@@ -46,34 +46,37 @@ app.use(function* (next) {
yield
next
;
yield
next
;
return
;
return
;
}
}
if
(
!
this
.
headers
[
'
application/json
'
]
)
{
if
(
this
.
headers
[
'
content-type
'
]
||
!~
this
.
headers
[
'
content-type
'
].
indexOf
(
'
application/json
'
)
)
{
this
.
status
=
400
;
this
.
status
=
400
;
this
.
body
=
{
this
.
body
=
{
code
:
400
,
code
:
400
,
message
:
'
invalid content type, should be application/json
'
message
:
'
invalid content type, should be application/json
'
};
};
yield
next
;
return
yield
next
;
return
;
}
}
let
rawData
=
''
;
try
{
const
body
=
yield
new
Promise
((
resolve
,
reject
)
=>
{
this
.
req
.
on
(
'
data
'
,
chunk
=>
{
let
rawData
=
''
;
rawData
+=
chunk
.
toString
();
this
.
req
.
on
(
'
data
'
,
chunk
=>
{
});
rawData
+=
chunk
.
toString
();
this
.
req
.
on
(
'
end
'
,
()
=>
{
});
try
{
this
.
req
.
on
(
'
end
'
,
()
=>
{
this
.
req
.
body
=
JSON
.
parse
(
rawData
);
try
{
next
();
resolve
(
JSON
.
parse
(
rawData
));
return
;
}
catch
(
err
)
{
}
catch
(
err
)
{
reject
({
this
.
body
=
{
code
:
400
,
code
:
400
,
message
:
'
invalid body data, should be a valid JSON string
'
message
:
'
invalid body data, should be a valid JSON string
'
});
};
}
this
.
status
=
400
;
});
}
});
});
this
.
req
.
body
=
body
;
}
catch
(
e
)
{
this
.
status
=
400
;
this
.
body
=
e
;
}
});
});
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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