Skip to content

Commit

Permalink
Body should be non-frozen by default. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 27, 2023
1 parent 9501735 commit af5d2f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/webrick/httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def initialize(config)
@status = HTTPStatus::RC_OK
@reason_phrase = nil
@http_version = HTTPVersion::convert(@config[:HTTPVersion])
@body = ''
@body = +""
@keep_alive = true
@cookies = []
@request_method = nil
Expand Down Expand Up @@ -441,7 +441,7 @@ def check_header(header_value)
# :stopdoc:

def error_body(backtrace, ex, host, port)
@body = +''
@body = +""
@body << <<-_end_of_html_
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
Expand Down
4 changes: 4 additions & 0 deletions test/webrick/test_httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def setup
@res.keep_alive = true
end

def test_response_body_not_frozen
refute @res.body.frozen?
end

def test_prevent_response_splitting_headers_crlf
res['X-header'] = "malicious\r\nCookie: cracked_indicator_for_test"
io = StringIO.new
Expand Down

0 comments on commit af5d2f5

Please # to comment.