File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,44 @@ http {
85
85
assert(ok and not err)
86
86
}
87
87
}
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
+ }
88
126
}
89
127
}
90
128
```
You can’t perform that action at this time.
0 commit comments