Debian Codegraph @

doc/src/manual/cowboy_stream.data.asciidoc

raw
1 = cowboy_stream:data(3)
2
3 == Name
4
5 cowboy_stream:data - Handle data for a stream
6
7 == Description
8
9 [source,erlang]
10 ----
11 data(StreamID, IsFin, Data, State) -> {Commands, State}
12
13 StreamID :: cowboy_stream:stream_id()
14 IsFin :: cowboy_stream:fin()
15 Data :: binary()
16 Commands :: cowboy_stream:commands()
17 State - opaque
18 ----
19
20 Handle data for a stream.
21
22 This function should be called by all stream handlers. It will
23 propagate data to the next configured stream handler. Handlers
24 do not have to propagate data that has been fully handled.
25
26 == Arguments
27
28 StreamID::
29
30 The stream ID.
31
32 IsFin::
33
34 Whether this is the end of the request body.
35
36 Data::
37
38 The data received.
39
40 Commands::
41
42 The commands to be executed.
43
44 State::
45
46 The state for the next stream handler.
47
48 == Return value
49
50 A list of commands and an opaque state is returned.
51
52 The list of commands returned should be included in the
53 commands returned from the current stream handler. It
54 can be modified if necessary.
55
56 The state should be stored in the current stream
57 handler's state and passed to `cowboy_stream` when
58 necessary. The state should be treated as opaque.
59
60 == Changelog
61
62 * *2.0*: Function introduced.
63
64 == Examples
65
66 .Propagate data to the next stream handler
67 [source,erlang]
68 ----
69 data(StreamID, IsFin, Data, State=#state{next=Next0}) ->
70 MyCommands = my_commands(),
71 {Commands, Next} = cowboy_stream:data(StreamID, IsFin, Data, Next0),
72 {MyCommands ++ Commands, #state{next=Next}}.
73 ----
74
75 == See also
76
77 link:man:cowboy_stream(3)[cowboy_stream(3)],
78 link:man:cowboy_stream:init(3)[cowboy_stream:init(3)],
79 link:man:cowboy_stream:info(3)[cowboy_stream:info(3)],
80 link:man:cowboy_stream:terminate(3)[cowboy_stream:terminate(3)],
81 link:man:cowboy_stream:early_error(3)[cowboy_stream:early_error(3)]