diff options
| author | _Tradam <[email protected]> | 2021-12-16 19:22:26 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-16 19:22:26 -0500 |
| commit | 5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch) | |
| tree | fecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/11_http/02_in_game_web_server_http_get | |
| parent | 2f845281f133849256b57bb08fd3e9ae57600784 (diff) | |
| parent | eaa29e72939f5edf61735ccbb73c36ee89369f65 (diff) | |
| download | dragonruby-game-toolkit-contrib-master.tar.gz dragonruby-game-toolkit-contrib-master.zip | |
Diffstat (limited to 'samples/11_http/02_in_game_web_server_http_get')
| -rw-r--r-- | samples/11_http/02_in_game_web_server_http_get/app/main.rb | 28 | ||||
| -rw-r--r-- | samples/11_http/02_in_game_web_server_http_get/license-for-sample.txt | 9 |
2 files changed, 37 insertions, 0 deletions
diff --git a/samples/11_http/02_in_game_web_server_http_get/app/main.rb b/samples/11_http/02_in_game_web_server_http_get/app/main.rb new file mode 100644 index 0000000..7fd67f7 --- /dev/null +++ b/samples/11_http/02_in_game_web_server_http_get/app/main.rb @@ -0,0 +1,28 @@ +def tick args + args.state.port ||= 3000 + args.state.reqnum ||= 0 + # by default the embedded webserver runs on port 9001 (the port number is over 9000) and is disabled in a production build + # to enable the http server in a production build, you need to manually start + # the server up: + args.gtk.start_server! port: args.state.port, enable_in_prod: true + args.outputs.background_color = [0, 0, 0] + args.outputs.labels << [640, 600, "Point your web browser at http://localhost:#{args.state.port}/", 10, 1, 255, 255, 255] + + args.inputs.http_requests.each { |req| + puts("METHOD: #{req.method}"); + puts("URI: #{req.uri}"); + puts("HEADERS:"); + req.headers.each { |k,v| puts(" #{k}: #{v}") } + + if (req.uri == '/') + # headers and body can be nil if you don't care about them. + # If you don't set the Content-Type, it will default to + # "text/html; charset=utf-8". + # Don't set Content-Length; we'll ignore it and calculate it for you + args.state.reqnum += 1 + req.respond 200, "<html><head><title>hello</title></head><body><h1>This #{req.method} was request number #{args.state.reqnum}!</h1></body></html>\n", { 'X-DRGTK-header' => 'Powered by DragonRuby!' } + else + req.reject + end + } +end diff --git a/samples/11_http/02_in_game_web_server_http_get/license-for-sample.txt b/samples/11_http/02_in_game_web_server_http_get/license-for-sample.txt new file mode 100644 index 0000000..175ac25 --- /dev/null +++ b/samples/11_http/02_in_game_web_server_http_get/license-for-sample.txt @@ -0,0 +1,9 @@ +Copyright 2021 DragonRuby LLC + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
