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
acbd0c67
Commit
acbd0c67
authored
May 12, 2016
by
Yoshiharu Hirose
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
アップロード要求に応答する
parent
bcc80266
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
17 deletions
+51
-17
DummyHttpServer.scala
src/main/scala/DummyHttpServer.scala
+51
-17
No files found.
src/main/scala/DummyHttpServer.scala
View file @
acbd0c67
...
@@ -64,7 +64,7 @@ object DummyHttpServer {
...
@@ -64,7 +64,7 @@ object DummyHttpServer {
if
(
t
.
getRequestMethod
==
"GET"
)
{
if
(
t
.
getRequestMethod
==
"GET"
)
{
val
q
=
parseQuery
(
t
.
getRequestURI
.
getRawQuery
)
val
q
=
parseQuery
(
t
.
getRequestURI
.
getRawQuery
)
if
(
q
.
nonEmpty
)
{
if
(
q
.
nonEmpty
)
{
println
(
"-- Quer
y
"
)
println
(
"-- Quer
ies
"
)
q
.
foreach
{
case
(
k
,
v
)
=>
q
.
foreach
{
case
(
k
,
v
)
=>
printf
(
"%s: %s\n"
,
k
,
v
)
printf
(
"%s: %s\n"
,
k
,
v
)
}
}
...
@@ -77,34 +77,36 @@ object DummyHttpServer {
...
@@ -77,34 +77,36 @@ object DummyHttpServer {
println
(
"-- Body"
)
println
(
"-- Body"
)
println
(
body
)
println
(
body
)
val
ctype
=
t
.
getRequestHeaders
.
getFirst
(
"content-type"
)
if
(
ctype
==
null
||
ctype
.
matches
(
"application/x-www-form-urlencoded.*"
))
{
val
q
=
parseQuery
(
body
)
val
q
=
parseQuery
(
body
)
if
(
q
.
nonEmpty
)
{
if
(
q
.
nonEmpty
)
{
println
(
"-- Query
"
)
println
(
"-- Queries (parsed body)
"
)
q
.
foreach
{
case
(
k
,
v
)
=>
q
.
foreach
{
case
(
k
,
v
)
=>
printf
(
"%s: %s\n"
,
k
,
v
)
printf
(
"%s: %s\n"
,
k
,
v
)
}
}
}
actionOps
=
q
.
get
(
"Action"
)
actionOps
=
q
.
get
(
"Action"
)
}
}
}
}
}
}
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
)).
orElse
{
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
)).
orElse
{
actionOps
.
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
)
replyFile
(
t
,
file
)
val
is
=
new
BufferedInputStream
(
new
FileInputStream
(
file
))
val
os
=
t
.
getResponseBody
val
buf
=
new
Array
[
Byte
](
file
.
length
.
toInt
)
is
.
read
(
buf
)
os
.
write
(
buf
)
os
.
close
()
is
.
close
()
printf
(
" -> 200 (%s)\n"
,
file
.
getAbsolutePath
)
printf
(
" -> 200 (%s)\n"
,
file
.
getAbsolutePath
)
case
_
=>
case
_
=>
if
(
t
.
getRequestHeaders
.
getFirst
(
"X-nifty-upload-id"
)
!=
null
&&
t
.
getRequestHeaders
.
getFirst
(
"X-nifty-upload-operation"
)
!=
null
)
{
replyUpload
(
t
)
printf
(
" -> 200\n"
)
}
else
{
t
.
sendResponseHeaders
(
404
,
0
)
t
.
sendResponseHeaders
(
404
,
0
)
printf
(
" -> 404\n"
)
printf
(
" -> 404\n"
)
}
}
}
}
catch
{
}
catch
{
case
e
:
Throwable
=>
case
e
:
Throwable
=>
t
.
sendResponseHeaders
(
500
,
0
)
t
.
sendResponseHeaders
(
500
,
0
)
...
@@ -114,6 +116,38 @@ object DummyHttpServer {
...
@@ -114,6 +116,38 @@ object DummyHttpServer {
t
.
close
()
t
.
close
()
}
}
/**
* ファイルの中身を返す
*
* @param t HttpExchange
* @param file ファイル
*/
def
replyFile
(
t
:
HttpExchange
,
file
:
File
)
:
Unit
=
{
t
.
sendResponseHeaders
(
200
,
file
.
length
)
val
is
=
new
BufferedInputStream
(
new
FileInputStream
(
file
))
val
os
=
t
.
getResponseBody
val
buf
=
new
Array
[
Byte
](
file
.
length
.
toInt
)
is
.
read
(
buf
)
os
.
write
(
buf
)
os
.
close
()
is
.
close
()
}
/**
* アップロード要求に応答
*
* @param t HttpExchange
*/
def
replyUpload
(
t
:
HttpExchange
)
:
Unit
=
{
t
.
getResponseHeaders
.
add
(
"x-nifty-upload-applet-blocksize"
,
"0"
)
t
.
getResponseHeaders
.
add
(
"x-nifty-upload-applet-timeout"
,
"0"
)
t
.
getResponseHeaders
.
add
(
"x-nifty-upload-applet-socketbufsize"
,
"0"
)
t
.
getResponseHeaders
.
add
(
"x-nifty-upload-next-position"
,
"0"
)
t
.
getResponseHeaders
.
add
(
"x-nifty-upload-result-code"
,
"200"
)
t
.
getResponseHeaders
.
add
(
"x-nifty-upload-result-msg"
,
"ok."
)
t
.
sendResponseHeaders
(
200
,
0
)
}
/**
/**
* ファイル検索
* ファイル検索
*
*
...
...
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