Skip to content

Commit 8a38cc7

Browse files
committed
doc: supplied synposis
1 parent 9f01365 commit 8a38cc7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.markdown

+38
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,44 @@ http {
8585
assert(ok and not err)
8686
}
8787
}
88+
89+
location /write {
90+
content_by_lua_block {
91+
local ngx_io = require "ngx.io"
92+
93+
local length = tonumber(ngx.var.http_content_length)
94+
if not length then
95+
return ngx.exit(200)
96+
end
97+
98+
local sock, err = ngx.req.socket()
99+
if not sock then
100+
ngx.log(ngx.ERR, "ngx.req.socket() failed: ", err)
101+
return ngx.exit(500)
102+
end
103+
104+
local file, err = ngx_io.open("/tmp/foo.txt", "w")
105+
assert(file and not err)
106+
107+
repeat
108+
local size = length > 4096 and 4096 or length
109+
length = length - size
110+
local data, err = sock:receive(size)
111+
if err then
112+
ngx.log(ngx.ERR, "sock:receive() failed: ", err)
113+
return
114+
end
115+
116+
local bytes, err = file:write(data)
117+
assert(bytes == size)
118+
assert(not err)
119+
until length == 0
120+
121+
local ok, err = file:close()
122+
assert(ok and not err)
123+
124+
return ngx.exit(200)
125+
}
88126
}
89127
}
90128
```

0 commit comments

Comments
 (0)