2
2
#include <apr_bucket_nginx.h>
3
3
4
4
static apr_status_t nginx_bucket_read (apr_bucket * b , const char * * str ,
5
- apr_size_t * len , apr_read_type_e block );
5
+ apr_size_t * len , apr_read_type_e block );
6
6
static void nginx_bucket_destroy (void * data );
7
7
8
8
static const apr_bucket_type_t apr_bucket_type_nginx = {
@@ -110,22 +110,22 @@ ngx_buf_t * apr_bucket_to_ngx_buf(apr_bucket *e, ngx_pool_t *pool) {
110
110
b -> last_buf = 0 ;
111
111
return b ;
112
112
}
113
-
113
+
114
114
buf = ngx_palloc (pool , sizeof (ngx_buf_t ));
115
115
if (buf == NULL ) {
116
116
return NULL ;
117
117
}
118
118
ngx_memcpy (buf , b , sizeof (ngx_buf_t ));
119
-
120
- if (ngx_buf_in_memory (buf )) {
119
+
120
+ if (ngx_buf_in_memory (buf )) {
121
121
buf -> start = buf -> pos = buf -> pos + e -> start ;
122
122
buf -> end = buf -> last = buf -> pos + e -> length ;
123
123
} else {
124
124
buf -> pos = NULL ;
125
125
buf -> file_pos += e -> start ;
126
126
buf -> file_last = buf -> file_pos + e -> length ;
127
127
}
128
-
128
+
129
129
buf -> last_buf = 0 ;
130
130
return buf ;
131
131
}
@@ -134,7 +134,7 @@ ngx_buf_t * apr_bucket_to_ngx_buf(apr_bucket *e, ngx_pool_t *pool) {
134
134
& len , APR_BLOCK_READ ) != APR_SUCCESS ) {
135
135
return NULL ;
136
136
}
137
-
137
+
138
138
buf = ngx_calloc_buf (pool );
139
139
if (buf == NULL ) {
140
140
return NULL ;
@@ -146,18 +146,18 @@ ngx_buf_t * apr_bucket_to_ngx_buf(apr_bucket *e, ngx_pool_t *pool) {
146
146
buf -> start = ngx_palloc (pool , len );
147
147
ngx_memcpy (buf -> start , data , len );
148
148
}
149
-
149
+
150
150
buf -> pos = buf -> start ;
151
151
buf -> end = buf -> last = buf -> start + len ;
152
152
buf -> temporary = 1 ;
153
153
return buf ;
154
154
}
155
155
156
156
ngx_int_t
157
- move_chain_to_brigade (ngx_chain_t * chain , apr_bucket_brigade * bb , ngx_pool_t * pool ) {
157
+ move_chain_to_brigade (ngx_chain_t * chain , apr_bucket_brigade * bb , ngx_pool_t * pool , ngx_int_t last_buf ) {
158
158
apr_bucket * e ;
159
159
ngx_chain_t * cl ;
160
-
160
+
161
161
while (chain ) {
162
162
e = ngx_buf_to_apr_bucket (chain -> buf , bb -> p , bb -> bucket_alloc );
163
163
if (e == NULL ) {
@@ -175,6 +175,13 @@ move_chain_to_brigade(ngx_chain_t *chain, apr_bucket_brigade *bb, ngx_pool_t *po
175
175
chain = chain -> next ;
176
176
ngx_free_chain (pool , cl );
177
177
}
178
+
179
+ if (last_buf ) {
180
+ e = apr_bucket_eos_create (bb -> bucket_alloc );
181
+ APR_BRIGADE_INSERT_TAIL (bb , e );
182
+ return NGX_OK ;
183
+ }
184
+
178
185
return NGX_AGAIN ;
179
186
}
180
187
@@ -185,16 +192,16 @@ move_brigade_to_chain(apr_bucket_brigade *bb, ngx_chain_t **ll, ngx_pool_t *pool
185
192
ngx_chain_t * cl ;
186
193
187
194
cl = NULL ;
188
-
195
+
189
196
if (APR_BRIGADE_EMPTY (bb )) {
190
197
* ll = NULL ;
191
198
return NGX_OK ;
192
199
}
193
-
200
+
194
201
for (e = APR_BRIGADE_FIRST (bb );
195
202
e != APR_BRIGADE_SENTINEL (bb );
196
203
e = APR_BUCKET_NEXT (e )) {
197
-
204
+
198
205
if (APR_BUCKET_IS_EOS (e )) {
199
206
if (cl == NULL ) {
200
207
* ll = cl ;
@@ -204,7 +211,7 @@ move_brigade_to_chain(apr_bucket_brigade *bb, ngx_chain_t **ll, ngx_pool_t *pool
204
211
apr_brigade_cleanup (bb );
205
212
return NGX_OK ;
206
213
}
207
-
214
+
208
215
if (APR_BUCKET_IS_METADATA (e )) {
209
216
continue ;
210
217
}
@@ -213,12 +220,12 @@ move_brigade_to_chain(apr_bucket_brigade *bb, ngx_chain_t **ll, ngx_pool_t *pool
213
220
if (buf == NULL ) {
214
221
break ;
215
222
}
216
-
223
+
217
224
cl = ngx_alloc_chain_link (pool );
218
225
if (cl == NULL ) {
219
226
break ;
220
227
}
221
-
228
+
222
229
cl -> buf = buf ;
223
230
cl -> next = NULL ;
224
231
* ll = cl ;
0 commit comments