~ubuntu-branches/ubuntu/oneiric/squid3/oneiric-security

« back to all changes in this revision

Viewing changes to src/HttpReply.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mahyuddin Susanto
  • Date: 2011-02-15 18:46:13 UTC
  • mfrom: (21.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110215184613-1u3dh5sz4i055flk
Tags: 3.1.10-1ubuntu1
* Merge from debian unstable. (LP: #719283)  Remaining changes:
  - debian/patches/18-fix-ftbfs-binutils-gold.dpatch: Add library linker into
    LIBS instead to LDFLAGS to fixing FTBFS binutils-gold.
* Drop Ubuntu configuration for ufw which landed in Debian and sync it: 
  - debian/squid3.ufw.profile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
static http_hdr_type Denied304HeadersArr[] = {
63
63
    // hop-by-hop headers
64
64
    HDR_CONNECTION, HDR_KEEP_ALIVE, HDR_PROXY_AUTHENTICATE, HDR_PROXY_AUTHORIZATION,
65
 
    HDR_TE, HDR_TRAILERS, HDR_TRANSFER_ENCODING, HDR_UPGRADE,
 
65
    HDR_TE, HDR_TRAILER, HDR_TRANSFER_ENCODING, HDR_UPGRADE,
66
66
    // entity headers
67
67
    HDR_ALLOW, HDR_CONTENT_ENCODING, HDR_CONTENT_LANGUAGE, HDR_CONTENT_LENGTH,
68
68
    HDR_CONTENT_MD5, HDR_CONTENT_RANGE, HDR_CONTENT_TYPE, HDR_LAST_MODIFIED
186
186
    /* rv->content_range */
187
187
    /* rv->keep_alive */
188
188
    HttpVersion ver(1,0);
189
 
    httpStatusLineSet(&rv->sline, ver, HTTP_NOT_MODIFIED, "");
 
189
    httpStatusLineSet(&rv->sline, ver, HTTP_NOT_MODIFIED, NULL);
190
190
 
191
191
    for (t = 0; ImsEntries[t] != HDR_OTHER; ++t)
192
192
        if ((e = header.findEntry(ImsEntries[t])))
540
540
        expectBody = true;
541
541
 
542
542
    if (expectBody) {
543
 
        if (header.hasListMember(HDR_TRANSFER_ENCODING, "chunked", ','))
 
543
        if (header.chunked())
544
544
            theSize = -1;
545
545
        else if (content_length >= 0)
546
546
            theSize = content_length;
589
589
    bodySizeMax = -1;
590
590
 
591
591
    ACLFilledChecklist ch(NULL, &request, NULL);
592
 
    ch.src_addr = request.client_addr;
 
592
#if FOLLOW_X_FORWARDED_FOR
 
593
    if (Config.onoff.acl_uses_indirect_client)
 
594
        ch.src_addr = request.indirect_client_addr;
 
595
    else
 
596
#endif
 
597
        ch.src_addr = request.client_addr;
593
598
    ch.my_addr = request.my_addr;
594
599
    ch.reply = HTTPMSGLOCK(this); // XXX: this lock makes method non-const
595
600
    for (acl_size_t *l = Config.ReplyBodySize; l; l = l -> next) {
629
634
    keep_alive = aRep->keep_alive;
630
635
    return true;
631
636
}
 
637
 
 
638
void HttpReply::removeStaleWarnings()
 
639
{
 
640
    String warning;
 
641
    if (header.getList(HDR_WARNING, &warning)) {
 
642
        const String newWarning = removeStaleWarningValues(warning);
 
643
        if (warning.size() && warning.size() == newWarning.size())
 
644
            return; // some warnings are there and none changed
 
645
        header.delById(HDR_WARNING);
 
646
        if (newWarning.size()) { // some warnings left
 
647
            HttpHeaderEntry *const e =
 
648
                new HttpHeaderEntry(HDR_WARNING, NULL, newWarning.termedBuf());
 
649
            header.addEntry(e);
 
650
        }
 
651
    }
 
652
}
 
653
 
 
654
/**
 
655
 * Remove warning-values with warn-date different from Date value from
 
656
 * a single header entry. Returns a string with all valid warning-values.
 
657
 */
 
658
String HttpReply::removeStaleWarningValues(const String &value)
 
659
{
 
660
    String newValue;
 
661
    const char *item = 0;
 
662
    int len = 0;
 
663
    const char *pos = 0;
 
664
    while (strListGetItem(&value, ',', &item, &len, &pos)) {
 
665
        bool keep = true;
 
666
        // Does warning-value have warn-date (which contains quoted date)?
 
667
        // We scan backwards, looking for two quoted strings.
 
668
        // warning-value = warn-code SP warn-agent SP warn-text [SP warn-date]
 
669
        const char *p = item + len - 1;
 
670
 
 
671
        while (p >= item && xisspace(*p)) --p; // skip whitespace
 
672
 
 
673
        // warning-value MUST end with quote
 
674
        if (p >= item && *p == '"') {
 
675
            const char *const warnDateEnd = p;
 
676
            --p;
 
677
            while (p >= item && *p != '"') --p; // find the next quote
 
678
 
 
679
            const char *warnDateBeg = p + 1;
 
680
            --p;
 
681
            while (p >= item && xisspace(*p)) --p; // skip whitespace
 
682
 
 
683
            if (p >= item && *p == '"' && warnDateBeg - p > 2) {
 
684
                // found warn-text
 
685
                String warnDate;
 
686
                warnDate.append(warnDateBeg, warnDateEnd - warnDateBeg);
 
687
                const time_t time = parse_rfc1123(warnDate.termedBuf());
 
688
                keep = (time > 0 && time == date); // keep valid and matching date
 
689
            }
 
690
        }
 
691
 
 
692
        if (keep) {
 
693
            if (newValue.size())
 
694
                newValue.append(", ");
 
695
            newValue.append(item, len);
 
696
        }
 
697
    }
 
698
 
 
699
    return newValue;
 
700
}