@@ -71,6 +71,11 @@ def handle_request(socket)
71
71
socket . write "HTTP/1.1 100 Continue\r \n \r \n "
72
72
end
73
73
74
+ # Set default Content-Type if not provided
75
+ if !headers [ 'Content-Type' ] && ( method == 'POST' || method == 'PUT' || method == 'PATCH' )
76
+ headers [ 'Content-Type' ] = 'application/octet-stream'
77
+ end
78
+
74
79
req = Request . new ( method , path , headers , socket )
75
80
if @procs . key? ( req . path ) || @procs . key? ( "#{ req . path } /" )
76
81
proc = @procs [ req . path ] || @procs [ "#{ req . path } /" ]
@@ -306,16 +311,18 @@ def handle_post(path, headers, socket)
306
311
scheme = headers [ 'X-Request-Scheme' ] || 'http'
307
312
host = @config [ 'host' ]
308
313
port = socket . addr [ 1 ]
309
- charset = parse_content_type ( headers [ 'Content-Type' ] ) [ 1 ]
314
+ content_type = headers [ 'Content-Type' ] || 'application/octet-stream'
315
+ charset = parse_content_type ( content_type ) [ 1 ]
310
316
path = "#{ scheme } ://#{ host } :#{ port } #{ path } "
311
317
path = path . encode ( charset ) if charset
312
- response = "HTTP/1.1 200 OK\r \n Content-Type: #{ headers [ 'Content-Type' ] } \r \n Content-Length: #{ body . bytesize } \r \n X-request-uri: #{ path } \r \n \r \n #{ body } "
318
+ response = "HTTP/1.1 200 OK\r \n Content-Type: #{ content_type } \r \n Content-Length: #{ body . bytesize } \r \n X-request-uri: #{ path } \r \n \r \n #{ body } "
313
319
socket . print ( response )
314
320
end
315
321
316
322
def handle_patch ( path , headers , socket )
317
323
body = socket . read ( headers [ 'Content-Length' ] . to_i )
318
- response = "HTTP/1.1 200 OK\r \n Content-Type: #{ headers [ 'Content-Type' ] } \r \n Content-Length: #{ body . bytesize } \r \n \r \n #{ body } "
324
+ content_type = headers [ 'Content-Type' ] || 'application/octet-stream'
325
+ response = "HTTP/1.1 200 OK\r \n Content-Type: #{ content_type } \r \n Content-Length: #{ body . bytesize } \r \n \r \n #{ body } "
319
326
socket . print ( response )
320
327
end
321
328
0 commit comments