Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
Metrics
Website
Commits
b2f1b394
Commit
b2f1b394
authored
Jan 09, 2018
by
Karsten Loesing
Browse files
Avoid sending an error after a (partial) response.
Also take out some unused code. Fixes
#24823
.
parent
7dce6a5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
b2f1b394
# Changes in version ????
*
Minor changes
-
Avoid sending an error after a (partial) response.
# Changes in version 1.0.3 - 2017-12-20
*
Major changes
...
...
src/main/java/org/torproject/metrics/web/ResearchStatsServlet.java
View file @
b2f1b394
...
...
@@ -56,26 +56,16 @@ public class ResearchStatsServlet extends HttpServlet {
@Override
public
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
String
requestUri
=
request
.
getRequestURI
();
if
(
requestUri
.
equals
(
"/metrics/stats/"
))
{
this
.
writeDirectoryListing
(
request
,
response
);
File
statsFile
=
this
.
determineStatsFile
(
request
);
if
(
statsFile
==
null
)
{
response
.
sendError
(
HttpServletResponse
.
SC_NOT_FOUND
);
}
else
if
(!
statsFile
.
exists
())
{
response
.
sendError
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
}
else
{
File
statsFile
=
this
.
determineStatsFile
(
request
);
if
(
statsFile
==
null
)
{
response
.
sendError
(
HttpServletResponse
.
SC_NOT_FOUND
);
return
;
}
else
if
(!
this
.
writeStatsFile
(
statsFile
,
response
))
{
response
.
sendError
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
}
this
.
writeStatsFile
(
statsFile
,
response
);
}
}
private
void
writeDirectoryListing
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
response
.
setStatus
(
HttpServletResponse
.
SC_MOVED_PERMANENTLY
);
response
.
setHeader
(
"Location"
,
"/?type=dt&level=ad"
);
}
private
File
determineStatsFile
(
HttpServletRequest
request
)
{
String
requestedStatsFile
=
request
.
getRequestURI
();
if
(
requestedStatsFile
.
endsWith
(
".csv"
))
{
...
...
@@ -93,11 +83,8 @@ public class ResearchStatsServlet extends HttpServlet {
}
}
private
boolean
writeStatsFile
(
File
statsFile
,
private
void
writeStatsFile
(
File
statsFile
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
if
(!
statsFile
.
exists
())
{
return
false
;
}
response
.
setContentType
(
"text/csv"
);
response
.
setHeader
(
"Content-Length"
,
String
.
valueOf
(
statsFile
.
length
()));
...
...
@@ -112,10 +99,7 @@ public class ResearchStatsServlet extends HttpServlet {
while
((
length
=
bis
.
read
(
buffer
))
>
0
)
{
bos
.
write
(
buffer
,
0
,
length
);
}
}
catch
(
IOException
e
)
{
return
false
;
}
return
true
;
}
}
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