response_buckets.c (253895) | response_buckets.c (262324) |
---|---|
1/* Copyright 2002-2004 Justin Erenkrantz and Greg Stein 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * --- 29 unchanged lines hidden (view full) --- 38 serf_linebuf_t linebuf; 39 40 serf_status_line sl; 41 42 int chunked; /* Do we need to read trailers? */ 43 int head_req; /* Was this a HEAD request? */ 44} response_context_t; 45 | 1/* Copyright 2002-2004 Justin Erenkrantz and Greg Stein 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * --- 29 unchanged lines hidden (view full) --- 38 serf_linebuf_t linebuf; 39 40 serf_status_line sl; 41 42 int chunked; /* Do we need to read trailers? */ 43 int head_req; /* Was this a HEAD request? */ 44} response_context_t; 45 |
46/* Returns 1 if according to RFC2626 this response can have a body, 0 if it 47 must not have a body. */ 48static int expect_body(response_context_t *ctx) 49{ 50 if (ctx->head_req) 51 return 0; |
|
46 | 52 |
53 /* 100 Continue and 101 Switching Protocols */ 54 if (ctx->sl.code >= 100 && ctx->sl.code < 200) 55 return 0; 56 57 /* 204 No Content */ 58 if (ctx->sl.code == 204) 59 return 0; 60 61 /* 205? */ 62 63 /* 304 Not Modified */ 64 if (ctx->sl.code == 304) 65 return 0; 66 67 return 1; 68} 69 |
|
47serf_bucket_t *serf_bucket_response_create( 48 serf_bucket_t *stream, 49 serf_bucket_alloc_t *allocator) 50{ 51 response_context_t *ctx; 52 53 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx)); 54 ctx->stream = stream; --- 178 unchanged lines hidden (view full) --- 233 * Move on to the body. 234 */ 235 if (ctx->linebuf.state == SERF_LINEBUF_READY && !ctx->linebuf.used) { 236 const void *v; 237 238 /* Advance the state. */ 239 ctx->state = STATE_BODY; 240 | 70serf_bucket_t *serf_bucket_response_create( 71 serf_bucket_t *stream, 72 serf_bucket_alloc_t *allocator) 73{ 74 response_context_t *ctx; 75 76 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx)); 77 ctx->stream = stream; --- 178 unchanged lines hidden (view full) --- 256 * Move on to the body. 257 */ 258 if (ctx->linebuf.state == SERF_LINEBUF_READY && !ctx->linebuf.used) { 259 const void *v; 260 261 /* Advance the state. */ 262 ctx->state = STATE_BODY; 263 |
264 /* If this is a response to a HEAD request, or code == 1xx,204 or304 265 then we don't receive a real body. */ 266 if (!expect_body(ctx)) { 267 ctx->body = serf_bucket_simple_create(NULL, 0, NULL, NULL, 268 bkt->allocator); 269 ctx->state = STATE_BODY; 270 break; 271 } 272 |
|
241 ctx->body = 242 serf_bucket_barrier_create(ctx->stream, bkt->allocator); 243 244 /* Are we C-L, chunked, or conn close? */ 245 v = serf_bucket_headers_get(ctx->headers, "Content-Length"); 246 if (v) { 247 apr_uint64_t length; 248 length = apr_strtoi64(v, NULL, 10); --- 7 unchanged lines hidden (view full) --- 256 v = serf_bucket_headers_get(ctx->headers, "Transfer-Encoding"); 257 258 /* Need to handle multiple transfer-encoding. */ 259 if (v && strcasecmp("chunked", v) == 0) { 260 ctx->chunked = 1; 261 ctx->body = serf_bucket_dechunk_create(ctx->body, 262 bkt->allocator); 263 } | 273 ctx->body = 274 serf_bucket_barrier_create(ctx->stream, bkt->allocator); 275 276 /* Are we C-L, chunked, or conn close? */ 277 v = serf_bucket_headers_get(ctx->headers, "Content-Length"); 278 if (v) { 279 apr_uint64_t length; 280 length = apr_strtoi64(v, NULL, 10); --- 7 unchanged lines hidden (view full) --- 288 v = serf_bucket_headers_get(ctx->headers, "Transfer-Encoding"); 289 290 /* Need to handle multiple transfer-encoding. */ 291 if (v && strcasecmp("chunked", v) == 0) { 292 ctx->chunked = 1; 293 ctx->body = serf_bucket_dechunk_create(ctx->body, 294 bkt->allocator); 295 } |
264 265 if (!v && (ctx->sl.code == 204 || ctx->sl.code == 304)) { 266 ctx->state = STATE_DONE; 267 } | |
268 } 269 v = serf_bucket_headers_get(ctx->headers, "Content-Encoding"); 270 if (v) { 271 /* Need to handle multiple content-encoding. */ 272 if (v && strcasecmp("gzip", v) == 0) { 273 ctx->body = 274 serf_bucket_deflate_create(ctx->body, bkt->allocator, 275 SERF_DEFLATE_GZIP); 276 } 277 else if (v && strcasecmp("deflate", v) == 0) { 278 ctx->body = 279 serf_bucket_deflate_create(ctx->body, bkt->allocator, 280 SERF_DEFLATE_DEFLATE); 281 } 282 } | 296 } 297 v = serf_bucket_headers_get(ctx->headers, "Content-Encoding"); 298 if (v) { 299 /* Need to handle multiple content-encoding. */ 300 if (v && strcasecmp("gzip", v) == 0) { 301 ctx->body = 302 serf_bucket_deflate_create(ctx->body, bkt->allocator, 303 SERF_DEFLATE_GZIP); 304 } 305 else if (v && strcasecmp("deflate", v) == 0) { 306 ctx->body = 307 serf_bucket_deflate_create(ctx->body, bkt->allocator, 308 SERF_DEFLATE_DEFLATE); 309 } 310 } |
283 /* If we're a HEAD request, we don't receive a body. */ 284 if (ctx->head_req) { 285 ctx->state = STATE_DONE; 286 } | |
287 } 288 break; 289 case STATE_BODY: 290 /* Don't do anything. */ 291 break; 292 case STATE_TRAILERS: 293 status = fetch_headers(bkt, ctx); 294 if (SERF_BUCKET_READ_ERROR(status)) --- 170 unchanged lines hidden --- | 311 } 312 break; 313 case STATE_BODY: 314 /* Don't do anything. */ 315 break; 316 case STATE_TRAILERS: 317 status = fetch_headers(bkt, ctx); 318 if (SERF_BUCKET_READ_ERROR(status)) --- 170 unchanged lines hidden --- |