/
streaming.cr
34 lines (30 loc) · 998 Bytes
/
streaming.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Marten
module HTTP
class Response
# Represents a streaming HTTP response, with an iterator of strings as a content.
class Streaming < Response
# Returns the response's content iterator.
getter streamed_content
# Allows to override the response's content iterator.
setter streamed_content
def initialize(
@streamed_content : Iterator(String),
@content_type : String = DEFAULT_CONTENT_TYPE,
@status : Int32 = 200
)
super(content: "", content_type: @content_type, status: @status)
end
def content
raise NotImplementedError.new(
"This response has no content, please use the #streamed_content method instead."
)
end
def content=(val)
raise NotImplementedError.new(
"This response has no content, please use the #streamed_content= method instead."
)
end
end
end
end
end