19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/wildnet-server/http_handler.rb', line 19
def message_received context, event
unless event.message.kind_of?(HttpRequest)
chunk = event.message
chunk.content.readBytes(@upload_stream, chunk.content.capacity)
if chunk.isLast
@upload_stream.close
handle
end
return
end
request = event.message
@request = Request.new
@request["REQUEST_METHOD"] = request.getMethod.getName
@request["SCRIPT_NAME"] = ""
@request["PATH_INFO"] = request.getUri
@request["QUERY_STRING"] = ""
@request["SERVER_NAME"] = HttpHeaders.getHost request, "localhost"
@request["SERVER_PORT"] = 80
@request["rack.url_scheme"] = "http"
@request["rack.input"] = File.new(java.io.File.createTempFile("wildnet.", ".request", java.io.File.new(File.join(Rails.root, "tmp"))).getAbsolutePath())
@request["rack.errors"] = $stderr
@request["rack.multithread"] = true
@request["rack.multiprocess"] = false
@request["rack.run_once"] = false
@upload_stream = FileOutputStream.new(java.io.File.new(@request["rack.input"].path))
unless request.isChunked
request.content.readBytes(@upload_stream, request.getContent.capacity)
@upload_stream.close
end
if request. "X-For-Host"
@request["SERVER_NAME"] = request. "X-For-Host"
end
if request. "X-For-Scheme"
@request["rack.url_scheme"] = request. "X-For-Scheme"
end
if server_name = %r{(.+):([0-9]+)}.match(@request["SERVER_NAME"])
@request["SERVER_NAME"] = server_name[1]
@request["SERVER_PORT"] = server_name[2].to_i
end
if path_info = %r{(.+)\?(.+)}.match(@request["PATH_INFO"])
@request["PATH_INFO"] = path_info[1]
@request["QUERY_STRING"] = path_info[2]
end
if (@request["SERVER_PORT"] != 80 and @request["rack.url_scheme"] != "http") and (@request["SERVER_PORT"] != 443 and @request["rack.url_scheme"] != "https")
request. "Host"
request. "Host", @request["SERVER_NAME"] + ":" + @request["SERVER_PORT"]
else
request. "Host"
request. "Host", @request["SERVER_NAME"]
end
request..each do ||
name = .gsub("-", "_").upcase
if (name != "CONTENT_TYPE" and name != "CONTENT_LENGTH")
name = "HTTP_#{name}"
end
@request[name] = request.()
end
@request["rack.version"] = ::Rack::VERSION
@request["wildnet.context"] = context
@request["wildnet.response"] = HttpResponse.new(@request["wildnet.context"])
unless request.isChunked
handle
end
end
|