aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-02-01 10:37:15 +0100
committerEugen Wissner <belka@caraus.de>2025-02-01 10:37:15 +0100
commite9bf0d84b8bc456e958eda5b52a0e9218fab6163 (patch)
treee1f22039018a6a698e516387f49ee272b1d97c87 /bin
parent957a161ec181b03f8cf7ea5bae932c2d8408ada9 (diff)
downloadkazbek-e9bf0d84b8bc456e958eda5b52a0e9218fab6163.tar.gz
Add a mock server
Diffstat (limited to 'bin')
-rwxr-xr-xbin/mock_server.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/mock_server.rb b/bin/mock_server.rb
new file mode 100755
index 0000000..09f6b91
--- /dev/null
+++ b/bin/mock_server.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/. -}
+
+# frozen_string_literal: true
+
+require 'socket'
+require 'json'
+
+TCP_PORT = 8082
+
+server = TCPServer.new TCP_PORT
+
+puts "Provide some JSON and press Ctrl-D oder pipe the input via STDIN."
+response = ''
+
+while input = gets do
+ response += input
+end
+
+puts "Starting the server on #{TCP_PORT}."
+
+loop do
+ client = server.accept
+
+ puts 'Connection accepted'
+ puts client.gets
+
+ begin
+ client.print("HTTP/1.1 200 OK\r\n")
+ client.print("Content-Type: application/json\r\n")
+ client.print("Content-Length: #{response.bytesize}\r\n")
+ client.print("Connection: close\r\n")
+ client.print("\r\n")
+
+ response.each_char do |chunk|
+ client.print chunk
+ sleep 0.1
+ end
+
+ # client.print(response)
+ end
+
+ client.close
+end