This repository was archived by the owner on Oct 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -92,21 +92,33 @@ def http_server_thread
92
92
93
93
private
94
94
95
+ def send_headers ( socket , body , content_type , custom_headers )
96
+ headers = [ ]
97
+ headers . push 'HTTP/1.1 200 OK'
98
+ headers . push "Content-Type: #{ content_type } "
99
+ headers . push "Content-Length: #{ body . bytesize } "
100
+ headers += custom_headers unless custom_headers . nil?
101
+ headers . push 'Connection: close'
102
+
103
+ headers . each do |header |
104
+ socket . print "#{ header } \r \n "
105
+ end
106
+ end
107
+
95
108
def send_response ( response , socket )
96
109
content_type = 'text/plain'
97
110
body = ''
111
+ custom_headers = nil
98
112
99
113
if response . is_a? String
100
114
body = response
101
115
else
102
116
body = response [ :body ]
103
117
content_type = response [ :type ]
118
+ custom_headers = response [ :headers ]
104
119
end
105
120
106
- socket . print "HTTP/1.1 200 OK\r \n " \
107
- "Content-Type: #{ content_type } \r \n " \
108
- "Content-Length: #{ body . bytesize } \r \n " \
109
- "Connection: close\r \n "
121
+ send_headers ( socket , body , content_type , custom_headers )
110
122
socket . print "\r \n "
111
123
socket . print body
112
124
end
You can’t perform that action at this time.
0 commit comments