Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dummyhttpserver
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yoshiharu Hirose
dummyhttpserver
Commits
33e4876d
Commit
33e4876d
authored
Apr 27, 2016
by
Yoshiharu Hirose
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
POSTリクエストに対しても応答を返すようにした。
parent
76f826ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
+27
-12
DummyHttpServer.scala
src/main/scala/DummyHttpServer.scala
+27
-12
No files found.
src/main/scala/DummyHttpServer.scala
View file @
33e4876d
...
@@ -53,22 +53,36 @@ object DummyHttpServer {
...
@@ -53,22 +53,36 @@ object DummyHttpServer {
printf
(
"%s: %s\n"
,
ent
.
getKey
,
v
)
printf
(
"%s: %s\n"
,
ent
.
getKey
,
v
)
}
}
}
}
val
q
=
parseQuery
(
t
.
getRequestURI
.
getRawQuery
)
var
actionOps
:
Option
[
String
]
=
None
if
(
q
.
nonEmpty
)
{
if
(
t
.
getRequestMethod
==
"GET"
)
{
println
(
"-- Query"
)
val
q
=
parseQuery
(
t
.
getRequestURI
.
getRawQuery
)
q
.
foreach
{
case
(
k
,
v
)
=>
if
(
q
.
nonEmpty
)
{
printf
(
"%s: %s\n"
,
k
,
v
)
println
(
"-- Query"
)
q
.
foreach
{
case
(
k
,
v
)
=>
printf
(
"%s: %s\n"
,
k
,
v
)
}
}
actionOps
=
q
.
get
(
"Action"
)
}
else
{
val
reader
=
new
BufferedReader
(
new
InputStreamReader
(
t
.
getRequestBody
))
val
body
=
Iterator
.
continually
(
reader
.
read
()).
takeWhile
(
_
!=
-
1
).
map
(
_
.
toChar
).
mkString
(
""
)
if
(
body
.
length
>
0
)
{
println
(
"-- Body"
)
println
(
body
)
val
q
=
parseQuery
(
body
)
if
(
q
.
nonEmpty
)
{
println
(
"-- Query"
)
q
.
foreach
{
case
(
k
,
v
)
=>
printf
(
"%s: %s\n"
,
k
,
v
)
}
}
actionOps
=
q
.
get
(
"Action"
)
}
}
}
val
reader
=
new
BufferedReader
(
new
InputStreamReader
(
t
.
getRequestBody
))
val
body
=
Iterator
.
continually
(
reader
.
read
()).
takeWhile
(
_
!=
-
1
).
map
(
_
.
toChar
).
mkString
(
""
)
if
(
body
.
length
>
0
)
{
println
(
"-- Body"
)
println
(
body
)
}
}
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
)).
orElse
{
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
)).
orElse
{
q
.
get
(
"Action"
)
.
flatMap
{
action
=>
findFile
(
action
+
".xml"
,
new
File
(
basedir
))
}
actionOps
.
flatMap
{
action
=>
findFile
(
action
+
".xml"
,
new
File
(
basedir
))
}
}
match
{
}
match
{
case
Some
(
file
)
=>
case
Some
(
file
)
=>
t
.
sendResponseHeaders
(
200
,
file
.
length
)
t
.
sendResponseHeaders
(
200
,
file
.
length
)
...
@@ -88,6 +102,7 @@ object DummyHttpServer {
...
@@ -88,6 +102,7 @@ object DummyHttpServer {
case
e
:
Throwable
=>
case
e
:
Throwable
=>
t
.
sendResponseHeaders
(
500
,
0
)
t
.
sendResponseHeaders
(
500
,
0
)
printf
(
" -> 500 (%s)\n"
,
e
.
toString
)
printf
(
" -> 500 (%s)\n"
,
e
.
toString
)
e
.
printStackTrace
()
}
}
t
.
close
()
t
.
close
()
}
}
...
...
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