~chtsanti/squid/icap-max-connections

« back to all changes in this revision

Viewing changes to tools/squidclient.cc

  • Committer: Christos Tsantilas
  • Date: 2009-04-11 09:00:59 UTC
  • mfrom: (9294.1.333 trunk)
  • Revision ID: chtsanti@users.sourceforge.net-20090411090059-8n47p1kyy1cqfqkn
MergeĀ FromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
                break;
223
223
 
224
224
            case 'j':
225
 
               host = optarg;
226
 
               break;
 
225
                host = optarg;
 
226
                break;
227
227
 
228
228
            case 'V':
229
229
                if (optarg != NULL)
353
353
    }
354
354
 
355
355
    if (!host) {
356
 
       char *newhost = strstr(url, "://");
357
 
       if (newhost) {
358
 
           char *t;
359
 
           newhost += 3;
360
 
           newhost = strdup(newhost);
361
 
           t = newhost + strcspn(newhost, "@/?");
362
 
           if (*t == '@') {
363
 
               newhost = t + 1;
364
 
               t = newhost + strcspn(newhost, "@/?");
365
 
           }
366
 
           *t = '\0';
367
 
           host = newhost;
368
 
       }
 
356
        char *newhost = strstr(url, "://");
 
357
        if (newhost) {
 
358
            char *t;
 
359
            newhost += 3;
 
360
            newhost = strdup(newhost);
 
361
            t = newhost + strcspn(newhost, "@/?");
 
362
            if (*t == '@') {
 
363
                newhost = t + 1;
 
364
                t = newhost + strcspn(newhost, "@/?");
 
365
            }
 
366
            *t = '\0';
 
367
            host = newhost;
 
368
        }
369
369
    }
370
370
 
371
 
    if(version[0] == '-' || !version[0] || version[0] == '0') {
372
 
        /* HTTP/0.9, no headers, no version */
 
371
    if (version[0] == '-' || !version[0] || version[0] == '0') {
 
372
        /* HTTP/0.9, no headers, no version */
373
373
        snprintf(msg, BUFSIZ, "%s %s\r\n", method, url);
374
374
    } else {
375
375
        snprintf(msg, BUFSIZ, "%s %s HTTP/%s\r\n", method, url, version);
376
376
 
377
 
        if (host) {
378
 
            snprintf(buf, BUFSIZ, "Host: %s\r\n", host);
379
 
            strcat(msg,buf);
380
 
        }
381
 
 
382
 
        if (reload) {
383
 
            snprintf(buf, BUFSIZ, "Pragma: no-cache\r\n");
384
 
            strcat(msg, buf);
385
 
        }
386
 
        if (put_fd > 0) {
387
 
            snprintf(buf, BUFSIZ, "Content-length: %d\r\n", (int) sb.st_size);
388
 
            strcat(msg, buf);
389
 
        }
390
 
        if (opt_noaccept == 0) {
391
 
            snprintf(buf, BUFSIZ, "Accept: */*\r\n");
392
 
            strcat(msg, buf);
393
 
        }
394
 
        if (ims) {
395
 
            snprintf(buf, BUFSIZ, "If-Modified-Since: %s\r\n", mkrfc1123(ims));
396
 
            strcat(msg, buf);
397
 
        }
398
 
        if (max_forwards > -1) {
399
 
            snprintf(buf, BUFSIZ, "Max-Forwards: %d\r\n", max_forwards);
400
 
            strcat(msg, buf);
401
 
        }
402
 
        if (proxy_user) {
403
 
            const char *user = proxy_user;
404
 
            const char *password = proxy_password;
405
 
#if HAVE_GETPASS
406
 
            if (!password)
407
 
                password = getpass("Proxy password: ");
408
 
#endif
409
 
            if (!password) {
410
 
                fprintf(stderr, "ERROR: Proxy password missing\n");
411
 
                exit(1);
412
 
            }
413
 
            snprintf(buf, BUFSIZ, "%s:%s", user, password);
414
 
            snprintf(buf, BUFSIZ, "Proxy-Authorization: Basic %s\r\n", base64_encode(buf));
415
 
            strcat(msg, buf);
416
 
        }
417
 
        if (www_user) {
418
 
            const char *user = www_user;
419
 
            const char *password = www_password;
420
 
#if HAVE_GETPASS
421
 
            if (!password)
422
 
                password = getpass("WWW password: ");
423
 
#endif
424
 
            if (!password) {
425
 
                fprintf(stderr, "ERROR: WWW password missing\n");
426
 
                exit(1);
427
 
            }
428
 
            snprintf(buf, BUFSIZ, "%s:%s", user, password);
429
 
            snprintf(buf, BUFSIZ, "Authorization: Basic %s\r\n", base64_encode(buf));
430
 
            strcat(msg, buf);
431
 
        }
432
 
 
433
 
        /* HTTP/1.0 may need keep-alive */
434
 
        if (strcmp(version, "1.0") == 0) {
435
 
            if (keep_alive) {
436
 
                if (strchr(url, ':'))
437
 
                    snprintf(buf, BUFSIZ, "Proxy-Connection: keep-alive\r\n");
438
 
                else
439
 
                    strcat(msg, "Connection: keep-alive\r\n");
440
 
           }
441
 
        } else {
442
 
            if (!keep_alive)
443
 
                strcat(msg, "Connection: close\r\n");
444
 
        }
445
 
        strcat(msg, buf);
446
 
 
447
 
        strcat(msg, extra_hdrs);
448
 
        strcat(msg, "\r\n");
 
377
        if (host) {
 
378
            snprintf(buf, BUFSIZ, "Host: %s\r\n", host);
 
379
            strcat(msg,buf);
 
380
        }
 
381
 
 
382
        if (reload) {
 
383
            snprintf(buf, BUFSIZ, "Pragma: no-cache\r\n");
 
384
            strcat(msg, buf);
 
385
        }
 
386
        if (put_fd > 0) {
 
387
            snprintf(buf, BUFSIZ, "Content-length: %d\r\n", (int) sb.st_size);
 
388
            strcat(msg, buf);
 
389
        }
 
390
        if (opt_noaccept == 0) {
 
391
            snprintf(buf, BUFSIZ, "Accept: */*\r\n");
 
392
            strcat(msg, buf);
 
393
        }
 
394
        if (ims) {
 
395
            snprintf(buf, BUFSIZ, "If-Modified-Since: %s\r\n", mkrfc1123(ims));
 
396
            strcat(msg, buf);
 
397
        }
 
398
        if (max_forwards > -1) {
 
399
            snprintf(buf, BUFSIZ, "Max-Forwards: %d\r\n", max_forwards);
 
400
            strcat(msg, buf);
 
401
        }
 
402
        if (proxy_user) {
 
403
            const char *user = proxy_user;
 
404
            const char *password = proxy_password;
 
405
#if HAVE_GETPASS
 
406
            if (!password)
 
407
                password = getpass("Proxy password: ");
 
408
#endif
 
409
            if (!password) {
 
410
                fprintf(stderr, "ERROR: Proxy password missing\n");
 
411
                exit(1);
 
412
            }
 
413
            snprintf(buf, BUFSIZ, "%s:%s", user, password);
 
414
            snprintf(buf, BUFSIZ, "Proxy-Authorization: Basic %s\r\n", base64_encode(buf));
 
415
            strcat(msg, buf);
 
416
        }
 
417
        if (www_user) {
 
418
            const char *user = www_user;
 
419
            const char *password = www_password;
 
420
#if HAVE_GETPASS
 
421
            if (!password)
 
422
                password = getpass("WWW password: ");
 
423
#endif
 
424
            if (!password) {
 
425
                fprintf(stderr, "ERROR: WWW password missing\n");
 
426
                exit(1);
 
427
            }
 
428
            snprintf(buf, BUFSIZ, "%s:%s", user, password);
 
429
            snprintf(buf, BUFSIZ, "Authorization: Basic %s\r\n", base64_encode(buf));
 
430
            strcat(msg, buf);
 
431
        }
 
432
 
 
433
        /* HTTP/1.0 may need keep-alive */
 
434
        if (strcmp(version, "1.0") == 0) {
 
435
            if (keep_alive) {
 
436
                if (strchr(url, ':'))
 
437
                    snprintf(buf, BUFSIZ, "Proxy-Connection: keep-alive\r\n");
 
438
                else
 
439
                    strcat(msg, "Connection: keep-alive\r\n");
 
440
            }
 
441
        } else {
 
442
            if (!keep_alive)
 
443
                strcat(msg, "Connection: close\r\n");
 
444
        }
 
445
        strcat(msg, buf);
 
446
 
 
447
        strcat(msg, extra_hdrs);
 
448
        strcat(msg, "\r\n");
449
449
    }
450
450
 
451
451
    if (opt_verbose)