Deleted Added
sdiff udiff text old ( 256281 ) new ( 262339 )
full compact
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;
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
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
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 }
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 }
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 ---