Lines 16-23
Link Here
|
16 |
See http://devel.squid-cache.org/icap/ for further information |
16 |
See http://devel.squid-cache.org/icap/ for further information |
17 |
about the ICAP client project. |
17 |
about the ICAP client project. |
18 |
|
18 |
|
19 |
Patch last updated: 2007-01-24 |
19 |
Patch last updated: 2007-03-04 |
20 |
|
20 |
|
|
|
21 |
Note: the patchset needs manual adjustments once in a while because |
22 |
the ICAP developers develop against Squid-2-HEAD and not |
23 |
Squid-2.6. |
24 |
|
21 |
Index: errors/Azerbaijani/ERR_ICAP_FAILURE |
25 |
Index: errors/Azerbaijani/ERR_ICAP_FAILURE |
22 |
=================================================================== |
26 |
=================================================================== |
23 |
RCS file: errors/Azerbaijani/ERR_ICAP_FAILURE |
27 |
RCS file: errors/Azerbaijani/ERR_ICAP_FAILURE |
Lines 2709-2719
Link Here
|
2709 |
Index: src/http.c |
2713 |
Index: src/http.c |
2710 |
=================================================================== |
2714 |
=================================================================== |
2711 |
RCS file: /cvsroot/squid/squid/src/http.c,v |
2715 |
RCS file: /cvsroot/squid/squid/src/http.c,v |
2712 |
retrieving revision 1.49 |
2716 |
retrieving revision 1.58 |
2713 |
retrieving revision 1.28.4.11 |
2717 |
retrieving revision 1.28.4.13 |
2714 |
diff -p -u -b -r1.49 -r1.28.4.11 |
2718 |
diff -p -u -b -r1.58 -r1.28.4.13 |
2715 |
--- src/http.c 23 Oct 2006 21:53:15 -0000 1.49 |
2719 |
--- src/http.c 24 Feb 2007 11:52:43 -0000 1.58 |
2716 |
+++ src/http.c 3 Nov 2006 18:47:13 -0000 1.28.4.11 |
2720 |
+++ src/http.c 27 Feb 2007 21:57:26 -0000 1.28.4.13 |
2717 |
@@ -47,7 +47,7 @@ static CWCB httpSendRequestEntry; |
2721 |
@@ -47,7 +47,7 @@ static CWCB httpSendRequestEntry; |
2718 |
|
2722 |
|
2719 |
static PF httpReadReply; |
2723 |
static PF httpReadReply; |
Lines 2737-2803
Link Here
|
2737 |
delayClearNoDelay(fd); |
2741 |
delayClearNoDelay(fd); |
2738 |
#endif |
2742 |
#endif |
2739 |
if (httpState == NULL) |
2743 |
if (httpState == NULL) |
2740 |
@@ -80,6 +81,9 @@ httpStateFree(int fd, void *data) |
2744 |
@@ -81,6 +82,9 @@ httpStateFree(int fd, void *data) |
2741 |
requestUnlink(httpState->orig_request); |
|
|
2742 |
httpState->request = NULL; |
2745 |
httpState->request = NULL; |
2743 |
httpState->orig_request = NULL; |
2746 |
httpState->orig_request = NULL; |
|
|
2747 |
stringClean(&httpState->chunkhdr); |
2744 |
+#if HS_FEAT_ICAP |
2748 |
+#if HS_FEAT_ICAP |
2745 |
+ cbdataUnlock(httpState->icap_writer); |
2749 |
+ cbdataUnlock(httpState->icap_writer); |
2746 |
+#endif |
2750 |
+#endif |
2747 |
cbdataFree(httpState); |
2751 |
cbdataFree(httpState); |
2748 |
} |
2752 |
} |
2749 |
|
2753 |
|
2750 |
@@ -409,7 +413,7 @@ httpMakeVaryMark(request_t * request, Ht |
2754 |
@@ -410,7 +414,7 @@ httpMakeVaryMark(request_t * request, Ht |
2751 |
} |
2755 |
} |
2752 |
|
2756 |
|
2753 |
/* rewrite this later using new interfaces @?@ */ |
2757 |
/* rewrite this later using new interfaces @?@ */ |
2754 |
-static void |
2758 |
-static size_t |
2755 |
+void |
2759 |
+size_t |
2756 |
httpProcessReplyHeader(HttpStateData * httpState, const char *buf, int size) |
2760 |
httpProcessReplyHeader(HttpStateData * httpState, const char *buf, int size) |
2757 |
{ |
2761 |
{ |
2758 |
StoreEntry *entry = httpState->entry; |
2762 |
StoreEntry *entry = httpState->entry; |
2759 |
@@ -552,24 +556,35 @@ httpPconnTransferDone(HttpStateData * ht |
2763 |
@@ -640,11 +644,25 @@ httpAppendBody(HttpStateData * httpState |
2760 |
MemObject *mem = httpState->entry->mem_obj; |
2764 |
if (size > httpState->chunk_size) |
2761 |
HttpReply *reply = mem->reply; |
2765 |
size = httpState->chunk_size; |
2762 |
squid_off_t clen; |
2766 |
httpState->chunk_size -= size; |
2763 |
+ squid_off_t content_bytes_read; |
|
|
2764 |
debug(11, 3) ("httpPconnTransferDone: FD %d\n", httpState->fd); |
2765 |
debug(11, 5) ("httpPconnTransferDone: content_length=%" PRINTF_OFF_T "\n", |
2766 |
reply->content_length); |
2767 |
/* If we haven't seen the end of reply headers, we are not done */ |
2768 |
- if (httpState->reply_hdr_state < 2) |
2769 |
+ if (httpState->reply_hdr_state < 2) { |
2770 |
+ debug(11, 3) ("httpPconnTransferDone: reply_hdr_state=%d, returning 0\n", |
2771 |
+ httpState->reply_hdr_state); |
2772 |
return 0; |
2773 |
+ } |
2774 |
clen = httpReplyBodySize(httpState->request->method, reply); |
2775 |
+#ifdef HS_FEAT_ICAP |
2767 |
+#ifdef HS_FEAT_ICAP |
2776 |
+ if (httpState->icap_writer) { |
2768 |
+ if (httpState->icap_writer) { |
2777 |
+ content_bytes_read = httpState->icap_writer->fake_content_length; |
2769 |
+ debug(81, 5) ("calling icapRespModAddBodyData from %s:%d\n", __FILE__, __LINE__); |
2778 |
+ debug(11, 3) ("using fake conten length %" PRINTF_OFF_T "\n", content_bytes_read); |
2770 |
+ icapRespModAddBodyData(httpState->icap_writer, buf, size); |
2779 |
+ } else |
2771 |
+ httpState->icap_writer->fake_content_length += size; |
|
|
2772 |
+ } else |
2780 |
+#endif |
2773 |
+#endif |
2781 |
+ content_bytes_read = mem->inmem_hi; |
2774 |
storeAppend(httpState->entry, buf, size); |
2782 |
/* If the body size is unknown we must wait for EOF */ |
2775 |
buf += size; |
2783 |
if (clen < 0) |
2776 |
len -= size; |
2784 |
return 0; |
2777 |
} else if (httpState->chunk_size < 0) { |
2785 |
/* Barf if we got more than we asked for */ |
2778 |
/* non-chunked without content-length */ |
2786 |
- if (mem->inmem_hi > clen + reply->hdr_sz) |
2779 |
+#ifdef HS_FEAT_ICAP |
2787 |
+ if (content_bytes_read > clen + reply->hdr_sz) |
2780 |
+ if (httpState->icap_writer) { |
2788 |
return -1; |
2781 |
+ debug(81, 5) ("calling icapRespModAddBodyData from %s:%d\n", __FILE__, __LINE__); |
2789 |
/* If there is no message body, we can be persistent */ |
2782 |
+ icapRespModAddBodyData(httpState->icap_writer, buf, len); |
2790 |
if (0 == clen) |
2783 |
+ httpState->icap_writer->fake_content_length += len; |
2791 |
return 1; |
2784 |
+ } else |
2792 |
/* If the body size is known, we must wait until we've gotten all of it. */ |
2785 |
+#endif |
2793 |
- if (mem->inmem_hi < clen + reply->hdr_sz) |
2786 |
storeAppend(httpState->entry, buf, len); |
2794 |
+ if (content_bytes_read < clen + reply->hdr_sz) |
2787 |
len = 0; |
2795 |
return 0; |
2788 |
} else if (httpState->flags.chunked) { |
2796 |
/* We got it all */ |
2789 |
@@ -699,6 +717,15 @@ httpAppendBody(HttpStateData * httpState |
2797 |
return 1; |
2790 |
/* Don't know what to do with this data. Bail out */ |
2798 |
@@ -636,6 +651,17 @@ httpReadReply(int fd, void *data) |
2791 |
break; |
2799 |
delay_id delay_id; |
2792 |
} |
|
|
2793 |
+#if HS_FEAT_ICAP |
2794 |
+ if (httpState->icap_writer) { |
2795 |
+ if (!httpState->icap_writer->respmod.entry) { |
2796 |
+ debug(11, 3) ("httpReadReply: FD: %d: icap respmod aborded!\n", fd); |
2797 |
+ comm_close(fd); |
2798 |
+ return; |
2799 |
+ } |
2800 |
+ } else |
2801 |
+#endif |
2802 |
if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { |
2803 |
/* |
2804 |
* the above storeAppend() call could ABORT this entry, |
2805 |
@@ -720,6 +747,10 @@ httpAppendBody(HttpStateData * httpState |
2806 |
if (!httpState->chunk_size && !httpState->flags.chunked) |
2807 |
complete = 1; |
2808 |
if (!complete && len == 0) { |
2809 |
+#ifdef HS_FEAT_ICAP |
2810 |
+ if (httpState->icap_writer) |
2811 |
+ icapSendRespMod(httpState->icap_writer, 0); |
2812 |
+#endif |
2813 |
/* Wait for more data or EOF condition */ |
2814 |
if (httpState->flags.keepalive_broken) { |
2815 |
commSetTimeout(fd, 10, NULL, NULL); |
2816 |
@@ -779,6 +810,10 @@ httpAppendBody(HttpStateData * httpState |
2817 |
*/ |
2818 |
if (!entry->mem_obj->reply->keep_alive) |
2819 |
keep_alive = 0; |
2820 |
+#ifdef HS_FEAT_ICAP |
2821 |
+ if (httpState->icap_writer) |
2822 |
+ icapSendRespMod(httpState->icap_writer, 1); |
2823 |
+#endif |
2824 |
if (keep_alive) { |
2825 |
int pinned = 0; |
2826 |
#if LINUX_TPROXY |
2827 |
@@ -838,6 +873,17 @@ httpReadReply(int fd, void *data) |
2800 |
#endif |
2828 |
#endif |
|
|
2829 |
int buffer_filled; |
2801 |
|
2830 |
|
2802 |
+#if HS_FEAT_ICAP |
2831 |
+#if HS_FEAT_ICAP |
2803 |
+ if (httpState->icap_writer) { |
2832 |
+ if (httpState->icap_writer) { |
Lines 2813-2819
Link Here
|
2813 |
if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { |
2842 |
if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { |
2814 |
comm_close(fd); |
2843 |
comm_close(fd); |
2815 |
return; |
2844 |
return; |
2816 |
@@ -647,7 +673,35 @@ httpReadReply(int fd, void *data) |
2845 |
@@ -849,7 +895,35 @@ httpReadReply(int fd, void *data) |
2817 |
else |
2846 |
else |
2818 |
delay_id = delayMostBytesAllowed(entry->mem_obj, &read_sz); |
2847 |
delay_id = delayMostBytesAllowed(entry->mem_obj, &read_sz); |
2819 |
#endif |
2848 |
#endif |
Lines 2849-2857
Link Here
|
2849 |
errno = 0; |
2878 |
errno = 0; |
2850 |
statCounter.syscalls.sock.reads++; |
2879 |
statCounter.syscalls.sock.reads++; |
2851 |
len = FD_READ_METHOD(fd, buf, read_sz); |
2880 |
len = FD_READ_METHOD(fd, buf, read_sz); |
2852 |
@@ -664,7 +718,13 @@ httpReadReply(int fd, void *data) |
2881 |
@@ -868,7 +942,13 @@ httpReadReply(int fd, void *data) |
2853 |
clen >>= 1; |
|
|
2854 |
IOStats.Http.read_hist[bin]++; |
2882 |
IOStats.Http.read_hist[bin]++; |
|
|
2883 |
buf[len] = '\0'; |
2855 |
} |
2884 |
} |
2856 |
- if (!httpState->reply_hdr.size && len > 0 && fd_table[fd].uses > 1) { |
2885 |
- if (!httpState->reply_hdr.size && len > 0 && fd_table[fd].uses > 1) { |
2857 |
+#ifdef HS_FEAT_ICAP |
2886 |
+#ifdef HS_FEAT_ICAP |
Lines 2864-2945
Link Here
|
2864 |
/* Skip whitespace */ |
2893 |
/* Skip whitespace */ |
2865 |
while (len > 0 && xisspace(*buf)) |
2894 |
while (len > 0 && xisspace(*buf)) |
2866 |
xmemmove(buf, buf + 1, len--); |
2895 |
xmemmove(buf, buf + 1, len--); |
2867 |
@@ -694,6 +754,12 @@ httpReadReply(int fd, void *data) |
2896 |
@@ -971,12 +1051,49 @@ httpReadReply(int fd, void *data) |
2868 |
} else if (len == 0) { |
2897 |
commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); |
2869 |
/* Connection closed; retrieval done. */ |
2898 |
return; |
2870 |
httpState->eof = 1; |
|
|
2871 |
+#ifdef HS_FEAT_ICAP |
2872 |
+ if (httpState->icap_writer && cbdataValid(httpState->icap_writer)) { |
2873 |
+ debug(81, 3) ("httpReadReply: EOF for ICAP writer\n"); |
2874 |
+ icapSendRespMod(httpState->icap_writer, buf, len, 1); |
2875 |
+ } |
2876 |
+#endif |
2877 |
if (httpState->reply_hdr_state < 2) |
2878 |
/* |
2879 |
* Yes Henrik, there is a point to doing this. When we |
2880 |
@@ -746,7 +812,28 @@ httpReadReply(int fd, void *data) |
2881 |
EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT); |
2882 |
} |
2899 |
} |
2883 |
} |
|
|
2884 |
+#ifdef HS_FEAT_ICAP |
2900 |
+#ifdef HS_FEAT_ICAP |
2885 |
+ if (httpState->icap_writer) { |
2901 |
+ if (httpState->icap_writer) { |
2886 |
+ debug(81, 5) ("calling icapSendRespMod from %s:%d\n", __FILE__, __LINE__); |
2902 |
+ debug(81, 5) ("calling icapSendRespMod from %s:%d\n", __FILE__, __LINE__); |
2887 |
+ if (cbdataValid(httpState->icap_writer)) { |
2903 |
+ if (cbdataValid(httpState->icap_writer)) { |
2888 |
+ icapSendRespMod(httpState->icap_writer, buf, len, 0); |
2904 |
+ icapRespModAddResponceHeaders(httpState->icap_writer, buf, done); |
2889 |
+ httpState->icap_writer->fake_content_length += len; |
2905 |
+ httpState->icap_writer->fake_content_length += done; |
|
|
2906 |
+ } |
2890 |
+ } |
2907 |
+ } |
2891 |
+ } else |
|
|
2892 |
+#endif |
2908 |
+#endif |
2893 |
storeAppend(entry, buf, len); |
2909 |
} |
2894 |
+ |
2910 |
httpAppendBody(httpState, buf + done, len - done, buffer_filled); |
2895 |
+ |
2911 |
return; |
2896 |
+ debug(11, 5) ("httpReadReply: after storeAppend FD %d read %d\n", fd, len); |
|
|
2897 |
+#if HS_FEAT_ICAP |
2898 |
+ if (httpState->icap_writer) { |
2899 |
+ if (!httpState->icap_writer->respmod.entry) { |
2900 |
+ debug(11, 3) ("httpReadReply: FD: %d: icap respmod aborded!\n", fd); |
2901 |
+ comm_close(fd); |
2902 |
+ return; |
2903 |
+ } |
2904 |
+ } else |
2905 |
+#endif |
2906 |
if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { |
2907 |
/* |
2908 |
* the above storeAppend() call could ABORT this entry, |
2909 |
@@ -793,10 +880,21 @@ httpReadReply(int fd, void *data) |
2910 |
("httpReadReply: Excess data from \"%s %s\"\n", |
2911 |
RequestMethodStr[orig_request->method], |
2912 |
storeUrl(entry)); |
2913 |
+#ifdef HS_FEAT_ICAP |
2914 |
+ if (httpState->icap_writer) { |
2915 |
+ debug(81, 5) ("calling icapSendRespMod from %s:%d\n", __FILE__, __LINE__); |
2916 |
+ icapSendRespMod(httpState->icap_writer, buf, len, 0); |
2917 |
+ httpState->icap_writer->fake_content_length += len; |
2918 |
+ } else |
2919 |
+#endif |
2920 |
storeAppend(entry, buf, len); |
2921 |
keep_alive = 0; |
2922 |
} |
2923 |
} |
2924 |
+#ifdef HS_FEAT_ICAP |
2925 |
+ if (httpState->icap_writer) |
2926 |
+ icapSendRespMod(httpState->icap_writer, NULL, 0, 1); |
2927 |
+#endif |
2928 |
if (keep_alive) { |
2929 |
int pinned = 0; |
2930 |
#if LINUX_TPROXY |
2931 |
@@ -852,6 +950,10 @@ httpReadReply(int fd, void *data) |
2932 |
("httpReadReply: Excess data from \"%s %s\"\n", |
2933 |
RequestMethodStr[orig_request->method], |
2934 |
storeUrl(entry)); |
2935 |
+#ifdef HS_FEAT_ICAP |
2936 |
+ if (httpState->icap_writer) |
2937 |
+ icapSendRespMod(httpState->icap_writer, NULL, 0, 1); |
2938 |
+#endif |
2939 |
fwdComplete(httpState->fwd); |
2940 |
comm_close(fd); |
2941 |
return; |
2942 |
@@ -862,6 +964,34 @@ httpReadReply(int fd, void *data) |
2943 |
} |
2912 |
} |
2944 |
} |
2913 |
} |
2945 |
|
2914 |
|
Lines 2974-2980
Link Here
|
2974 |
/* This will be called when request write is complete. Schedule read of |
2943 |
/* This will be called when request write is complete. Schedule read of |
2975 |
* reply. */ |
2944 |
* reply. */ |
2976 |
static void |
2945 |
static void |
2977 |
@@ -889,6 +1019,63 @@ httpSendComplete(int fd, char *bufnotuse |
2946 |
@@ -1004,6 +1121,63 @@ httpSendComplete(int fd, char *bufnotuse |
2978 |
comm_close(fd); |
2947 |
comm_close(fd); |
2979 |
return; |
2948 |
return; |
2980 |
} else { |
2949 |
} else { |
Lines 3038-3044
Link Here
|
3038 |
/* |
3007 |
/* |
3039 |
* Set the read timeout here because it hasn't been set yet. |
3008 |
* Set the read timeout here because it hasn't been set yet. |
3040 |
* We only set the read timeout after the request has been |
3009 |
* We only set the read timeout after the request has been |
3041 |
@@ -897,8 +1084,18 @@ httpSendComplete(int fd, char *bufnotuse |
3010 |
@@ -1012,8 +1186,18 @@ httpSendComplete(int fd, char *bufnotuse |
3042 |
* the timeout for POST/PUT requests that have very large |
3011 |
* the timeout for POST/PUT requests that have very large |
3043 |
* request bodies. |
3012 |
* request bodies. |
3044 |
*/ |
3013 |
*/ |
Lines 3058-3064
Link Here
|
3058 |
} |
3027 |
} |
3059 |
httpState->flags.request_sent = 1; |
3028 |
httpState->flags.request_sent = 1; |
3060 |
} |
3029 |
} |
3061 |
@@ -1192,8 +1389,11 @@ httpBuildRequestHeader(request_t * reque |
3030 |
@@ -1317,8 +1501,11 @@ httpBuildRequestHeader(request_t * reque |
3062 |
if (!EBIT_TEST(cc->mask, CC_MAX_AGE)) { |
3031 |
if (!EBIT_TEST(cc->mask, CC_MAX_AGE)) { |
3063 |
const char *url = entry ? storeUrl(entry) : urlCanonical(orig_request); |
3032 |
const char *url = entry ? storeUrl(entry) : urlCanonical(orig_request); |
3064 |
httpHdrCcSetMaxAge(cc, getMaxAge(url)); |
3033 |
httpHdrCcSetMaxAge(cc, getMaxAge(url)); |
Lines 3070-3076
Link Here
|
3070 |
} |
3039 |
} |
3071 |
/* Set no-cache if determined needed but not found */ |
3040 |
/* Set no-cache if determined needed but not found */ |
3072 |
if (orig_request->flags.nocache && !httpHeaderHas(hdr_in, HDR_PRAGMA)) |
3041 |
if (orig_request->flags.nocache && !httpHeaderHas(hdr_in, HDR_PRAGMA)) |
3073 |
@@ -1319,6 +1519,7 @@ httpStart(FwdState * fwd) |
3042 |
@@ -1444,6 +1631,7 @@ httpStart(FwdState * fwd) |
3074 |
int fd = fwd->server_fd; |
3043 |
int fd = fwd->server_fd; |
3075 |
HttpStateData *httpState; |
3044 |
HttpStateData *httpState; |
3076 |
request_t *proxy_req; |
3045 |
request_t *proxy_req; |
Lines 3078-3084
Link Here
|
3078 |
request_t *orig_req = fwd->request; |
3047 |
request_t *orig_req = fwd->request; |
3079 |
debug(11, 3) ("httpStart: \"%s %s\"\n", |
3048 |
debug(11, 3) ("httpStart: \"%s %s\"\n", |
3080 |
RequestMethodStr[orig_req->method], |
3049 |
RequestMethodStr[orig_req->method], |
3081 |
@@ -1361,12 +1562,22 @@ httpStart(FwdState * fwd) |
3050 |
@@ -1486,12 +1674,22 @@ httpStart(FwdState * fwd) |
3082 |
httpState->request = requestLink(orig_req); |
3051 |
httpState->request = requestLink(orig_req); |
3083 |
httpState->orig_request = requestLink(orig_req); |
3052 |
httpState->orig_request = requestLink(orig_req); |
3084 |
} |
3053 |
} |
Lines 4458-4465
Link Here
|
4458 |
RCS file: src/icap_reqmod.c |
4427 |
RCS file: src/icap_reqmod.c |
4459 |
diff -N src/icap_reqmod.c |
4428 |
diff -N src/icap_reqmod.c |
4460 |
--- /dev/null 1 Jan 1970 00:00:00 -0000 |
4429 |
--- /dev/null 1 Jan 1970 00:00:00 -0000 |
4461 |
+++ src/icap_reqmod.c 12 Dec 2006 22:49:46 -0000 1.1.14.9 |
4430 |
+++ src/icap_reqmod.c 31 Jan 2007 18:11:13 -0000 1.1.14.10 |
4462 |
@@ -0,0 +1,990 @@ |
4431 |
@@ -0,0 +1,989 @@ |
4463 |
+ |
4432 |
+ |
4464 |
+/* |
4433 |
+/* |
4465 |
+ * $Id$ |
4434 |
+ * $Id$ |
Lines 4567-4573
Link Here
|
4567 |
+ * url here. |
4536 |
+ * url here. |
4568 |
+ */ |
4537 |
+ */ |
4569 |
+ http->uri = xstrdup(urlCanonical(icap->request)); |
4538 |
+ http->uri = xstrdup(urlCanonical(icap->request)); |
4570 |
+ http->log_uri = xstrndup(http->uri, MAX_URL); |
|
|
4571 |
+ http->range_iter.boundary = StringNull; |
4539 |
+ http->range_iter.boundary = StringNull; |
4572 |
+ http->request = requestLink(request ? request : icap->request); |
4540 |
+ http->request = requestLink(request ? request : icap->request); |
4573 |
+ http->flags.did_icap_reqmod = 1; |
4541 |
+ http->flags.did_icap_reqmod = 1; |
Lines 4588-4600
Link Here
|
4588 |
+ assert(http->conn->chr->next == NULL); |
4556 |
+ assert(http->conn->chr->next == NULL); |
4589 |
+ { |
4557 |
+ { |
4590 |
+ ConnStateData *dummyconn; |
4558 |
+ ConnStateData *dummyconn; |
4591 |
+ clientHttpRequest *H; |
4559 |
+ clientHttpRequest *H; |
4592 |
+ dummyconn = cbdataAlloc(ConnStateData); |
4560 |
+ dummyconn = cbdataAlloc(ConnStateData); |
4593 |
+ dummyconn->fd = icap->reqmod.client_fd; |
4561 |
+ dummyconn->fd = icap->reqmod.client_fd; |
4594 |
+ dummyconn->pinning.fd = -1; |
4562 |
+ dummyconn->pinning.fd = -1; |
4595 |
+ H=DLINK_HEAD(conn->reqs); |
4563 |
+ H = DLINK_HEAD(conn->reqs); |
4596 |
+ dlinkAddTail(H, &H->node, &dummyconn->reqs); |
4564 |
+ dlinkAddTail(H, &H->node, &dummyconn->reqs); |
4597 |
+ H->conn = dummyconn; |
4565 |
+ H->conn = dummyconn; |
4598 |
+ comm_add_close_handler(dummyconn->fd, connStateFree, dummyconn); |
4566 |
+ comm_add_close_handler(dummyconn->fd, connStateFree, dummyconn); |
4599 |
+ } |
4567 |
+ } |
4600 |
+ http->conn->chr = http; |
4568 |
+ http->conn->chr = http; |
Lines 4605-4611
Link Here
|
4605 |
+ http->conn->in.size = 0; |
4573 |
+ http->conn->in.size = 0; |
4606 |
+ http->conn->in.buf = NULL; |
4574 |
+ http->conn->in.buf = NULL; |
4607 |
+ http->conn->log_addr = icap->reqmod.log_addr; |
4575 |
+ http->conn->log_addr = icap->reqmod.log_addr; |
4608 |
+ dlinkAddTail(http, &http->node, &http->conn->reqs); |
4576 |
+ dlinkAddTail(http, &http->node, &http->conn->reqs); |
4609 |
+ comm_add_close_handler(http->conn->fd, connStateFree, http->conn); |
4577 |
+ comm_add_close_handler(http->conn->fd, connStateFree, http->conn); |
4610 |
+#endif |
4578 |
+#endif |
4611 |
+ http->icap_reqmod = NULL; |
4579 |
+ http->icap_reqmod = NULL; |
Lines 4732-4739
Link Here
|
4732 |
+ } |
4700 |
+ } |
4733 |
+ method = urlParseMethod(mstr); |
4701 |
+ method = urlParseMethod(mstr); |
4734 |
+ if (method == METHOD_NONE) { |
4702 |
+ if (method == METHOD_NONE) { |
4735 |
+ debug(81, 1) ("icapReqModParseHttpRequest: Unsupported method '%s'\n", |
4703 |
+ debug(81, 1) ("icapReqModParseHttpRequest: Unsupported method '%s' (%d)\n", |
4736 |
+ mstr); |
4704 |
+ mstr, strlen(mstr)); |
4737 |
+ icapReqModParseHttpError(icap, "error:unsupported-request-method"); |
4705 |
+ icapReqModParseHttpError(icap, "error:unsupported-request-method"); |
4738 |
+ xfree(inbuf); |
4706 |
+ xfree(inbuf); |
4739 |
+ return; |
4707 |
+ return; |
Lines 5340-5346
Link Here
|
5340 |
+ icapParseChunkedBody(icap, |
5308 |
+ icapParseChunkedBody(icap, |
5341 |
+ icapReqModMemBufAppend, &icap->reqmod.http_entity.buf); |
5309 |
+ icapReqModMemBufAppend, &icap->reqmod.http_entity.buf); |
5342 |
+ } |
5310 |
+ } |
5343 |
+ if (icap->chunk_size < 0 ) |
5311 |
+ if (icap->chunk_size < 0) |
5344 |
+ icap->flags.reqmod_http_entity_eof = 1; |
5312 |
+ icap->flags.reqmod_http_entity_eof = 1; |
5345 |
+ |
5313 |
+ |
5346 |
+ if (!icap->flags.reqmod_http_entity_eof) |
5314 |
+ if (!icap->flags.reqmod_http_entity_eof) |
Lines 5455-5462
Link Here
|
5455 |
RCS file: src/icap_respmod.c |
5423 |
RCS file: src/icap_respmod.c |
5456 |
diff -N src/icap_respmod.c |
5424 |
diff -N src/icap_respmod.c |
5457 |
--- /dev/null 1 Jan 1970 00:00:00 -0000 |
5425 |
--- /dev/null 1 Jan 1970 00:00:00 -0000 |
5458 |
+++ src/icap_respmod.c 26 Sep 2006 22:47:36 -0000 1.1.14.7 |
5426 |
+++ src/icap_respmod.c 31 Jan 2007 18:11:15 -0000 1.1.14.8 |
5459 |
@@ -0,0 +1,1058 @@ |
5427 |
@@ -0,0 +1,1018 @@ |
5460 |
+ |
5428 |
+ |
5461 |
+/* |
5429 |
+/* |
5462 |
+ * $Id$ |
5430 |
+ * $Id$ |
Lines 5539-5546
Link Here
|
5539 |
+} |
5507 |
+} |
5540 |
+ |
5508 |
+ |
5541 |
+static int |
5509 |
+static int |
5542 |
+buildRespModHeader(MemBuf * mb, IcapStateData * icap, char *buf, |
5510 |
+buildRespModHeader(MemBuf * mb, IcapStateData * icap) |
5543 |
+ ssize_t len, int theEnd) |
|
|
5544 |
+{ |
5511 |
+{ |
5545 |
+ MemBuf mb_hdr; |
5512 |
+ MemBuf mb_hdr; |
5546 |
+ char *client_addr; |
5513 |
+ char *client_addr; |
Lines 5551-5563
Link Here
|
5551 |
+ icap_service *service; |
5518 |
+ icap_service *service; |
5552 |
+ HttpReply *r; |
5519 |
+ HttpReply *r; |
5553 |
+ |
5520 |
+ |
5554 |
+ if (memBufIsNull(&icap->respmod.req_hdr_copy)) |
|
|
5555 |
+ memBufDefInit(&icap->respmod.req_hdr_copy); |
5556 |
+ |
5557 |
+ memBufAppend(&icap->respmod.req_hdr_copy, buf, len); |
5558 |
+ |
5559 |
+ if (icap->respmod.req_hdr_copy.size > 4 && strncmp(icap->respmod.req_hdr_copy.buf, "HTTP/", 5)) { |
5521 |
+ if (icap->respmod.req_hdr_copy.size > 4 && strncmp(icap->respmod.req_hdr_copy.buf, "HTTP/", 5)) { |
5560 |
+ debug(81, 3) ("buildRespModHeader: Non-HTTP-compliant header: '%s'\n", buf); |
5522 |
+ debug(81, 3) ("buildRespModHeader: Non-HTTP-compliant header: '%s'\n", icap->respmod.req_hdr_copy.buf); |
5561 |
+ /* |
5523 |
+ /* |
5562 |
+ *Possible we can consider that we did not have http responce headers |
5524 |
+ *Possible we can consider that we did not have http responce headers |
5563 |
+ *(maybe HTTP 0.9 protocol), lets returning -1... |
5525 |
+ *(maybe HTTP 0.9 protocol), lets returning -1... |
Lines 5572-5587
Link Here
|
5572 |
+ |
5534 |
+ |
5573 |
+ hlen = headersEnd(icap->respmod.req_hdr_copy.buf, |
5535 |
+ hlen = headersEnd(icap->respmod.req_hdr_copy.buf, |
5574 |
+ icap->respmod.req_hdr_copy.size); |
5536 |
+ icap->respmod.req_hdr_copy.size); |
5575 |
+ debug(81, 3) ("buildRespModHeader: headersEnd = %d(%s)\n", hlen, buf); |
5537 |
+ debug(81, 3) ("buildRespModHeader: headersEnd = %d(%s)\n", hlen, icap->respmod.req_hdr_copy.buf); |
5576 |
+ if (0 == hlen) |
5538 |
+ if (0 == hlen) |
5577 |
+ return 0; |
5539 |
+ return 0; |
5578 |
+ |
5540 |
+ |
5579 |
+ /* |
5541 |
+ consumed = hlen; |
5580 |
+ * calc how many bytes from this 'buf' went towards the |
5542 |
+ debug(81, 3) ("buildRespModHeader: consumed = %d (from %d)\n", consumed, icap->respmod.req_hdr_copy.size); |
5581 |
+ * reply header. |
|
|
5582 |
+ */ |
5583 |
+ consumed = hlen - (icap->respmod.req_hdr_copy.size - len); |
5584 |
+ debug(81, 3) ("buildRespModHeader: consumed = %d\n", consumed); |
5585 |
+ |
5543 |
+ |
5586 |
+ |
5544 |
+ |
5587 |
+ /* |
5545 |
+ /* |
Lines 5631-5653
Link Here
|
5631 |
+ memBufAppend(mb, crlf, 2); |
5589 |
+ memBufAppend(mb, crlf, 2); |
5632 |
+ memBufAppend(mb, mb_hdr.buf, mb_hdr.size); |
5590 |
+ memBufAppend(mb, mb_hdr.buf, mb_hdr.size); |
5633 |
+ memBufClean(&mb_hdr); |
5591 |
+ memBufClean(&mb_hdr); |
5634 |
+ |
|
|
5635 |
+ |
5636 |
+ return consumed; |
5592 |
+ return consumed; |
5637 |
+} |
5593 |
+} |
5638 |
+ |
5594 |
+ |
5639 |
+ |
|
|
5640 |
+void |
5595 |
+void |
5641 |
+icapSendRespMod(IcapStateData * icap, char *buf, int len, int theEnd) |
5596 |
+icapRespModAddResponceHeaders(IcapStateData * icap, char *buf, int len) |
5642 |
+{ |
5597 |
+{ |
5643 |
+ MemBuf mb; |
5598 |
+ if (memBufIsNull(&icap->respmod.req_hdr_copy)) |
5644 |
+#if ICAP_PREVIEW |
5599 |
+ memBufDefInit(&icap->respmod.req_hdr_copy); |
5645 |
+ int size; |
5600 |
+ memBufAppend(&icap->respmod.req_hdr_copy, buf, len); |
5646 |
+ const int preview_size = icap->preview_size; |
5601 |
+ if (len && icap->flags.copy_response) { |
5647 |
+#endif |
5602 |
+ if (memBufIsNull(&icap->respmod.resp_copy)) |
5648 |
+ debug(81, 5) ("icapSendRespMod: FD %d, len %d, theEnd %d\n", |
5603 |
+ memBufDefInit(&icap->respmod.resp_copy); |
5649 |
+ icap->icap_fd, len, theEnd); |
5604 |
+ memBufAppend(&icap->respmod.resp_copy, buf, len); |
|
|
5605 |
+ } |
5606 |
+} |
5650 |
+ |
5607 |
+ |
|
|
5608 |
+void |
5609 |
+icapRespModAddBodyData(IcapStateData * icap, char *buf, int len) |
5610 |
+{ |
5651 |
+ if (icap->flags.no_content) { |
5611 |
+ if (icap->flags.no_content) { |
5652 |
+ /* |
5612 |
+ /* |
5653 |
+ * ICAP server said there are no modifications to make, so |
5613 |
+ * ICAP server said there are no modifications to make, so |
Lines 5661-5668
Link Here
|
5661 |
+ icap->respmod.resp_copy.buf, icap->respmod.resp_copy.size); |
5621 |
+ icap->respmod.resp_copy.buf, icap->respmod.resp_copy.size); |
5662 |
+ icap->respmod.resp_copy.size = 0; |
5622 |
+ icap->respmod.resp_copy.size = 0; |
5663 |
+ } |
5623 |
+ } |
5664 |
+ debug(81, 5) ("icapSendRepMod: len=%d theEnd=%d write_pending=%d\n", |
|
|
5665 |
+ len, theEnd, icap->flags.write_pending); |
5666 |
+ if (len) { |
5624 |
+ if (len) { |
5667 |
+ /* |
5625 |
+ /* |
5668 |
+ * also copy any new data from the HTTP side |
5626 |
+ * also copy any new data from the HTTP side |
Lines 5672-5700
Link Here
|
5672 |
+ (void) icapReadReply2(icap); |
5630 |
+ (void) icapReadReply2(icap); |
5673 |
+ return; |
5631 |
+ return; |
5674 |
+ } |
5632 |
+ } |
5675 |
+ if (theEnd) { |
|
|
5676 |
+ if (icap->respmod.res_body_sz) |
5677 |
+ icap->flags.send_zero_chunk = 1; |
5678 |
+ icap->flags.http_server_eof = 1; |
5679 |
+ } |
5680 |
+ /* |
5681 |
+ * httpReadReply is going to call us with a chunk and then |
5682 |
+ * right away again with an EOF if httpPconnTransferDone() is true. |
5683 |
+ * Since the first write is already dispatched, we'll have to |
5684 |
+ * hack this in somehow. |
5685 |
+ */ |
5686 |
+ if (icap->flags.write_pending) { |
5687 |
+ debug(81, 3) ("icapSendRespMod: oops, write_pending=1\n"); |
5688 |
+ assert(theEnd); |
5689 |
+ assert(len == 0); |
5690 |
+ return; |
5691 |
+ } |
5692 |
+ if (!cbdataValid(icap)) { |
5693 |
+ debug(81, 3) ("icapSendRespMod: failed to establish connection?\n"); |
5694 |
+ return; |
5695 |
+ } |
5696 |
+ memBufDefInit(&mb); |
5697 |
+ |
5698 |
+#if SUPPORT_ICAP_204 || ICAP_PREVIEW |
5633 |
+#if SUPPORT_ICAP_204 || ICAP_PREVIEW |
5699 |
+ /* |
5634 |
+ /* |
5700 |
+ * make a copy of the response in case ICAP server gives us a 204 |
5635 |
+ * make a copy of the response in case ICAP server gives us a 204 |
Lines 5715-5723
Link Here
|
5715 |
+ } |
5650 |
+ } |
5716 |
+#endif |
5651 |
+#endif |
5717 |
+ |
5652 |
+ |
|
|
5653 |
+ if (buf && len > 0) |
5654 |
+ memBufAppend(&icap->respmod.buffer, buf, len); |
5655 |
+} |
5656 |
+ |
5657 |
+ |
5658 |
+void |
5659 |
+icapSendRespMod(IcapStateData * icap, int theEnd) |
5660 |
+{ |
5661 |
+ MemBuf mb; |
5662 |
+#if ICAP_PREVIEW |
5663 |
+ int size; |
5664 |
+ const int preview_size = icap->preview_size; |
5665 |
+#endif |
5666 |
+ if (icap->flags.no_content) { |
5667 |
+ return; |
5668 |
+ } |
5669 |
+ debug(81, 5) ("icapSendRespMod: FD %d, theEnd %d\n", |
5670 |
+ icap->icap_fd, theEnd); |
5671 |
+ |
5672 |
+ /* |
5673 |
+ * httpReadReply is going to call us with a chunk and then |
5674 |
+ * right away again with an EOF if httpPconnTransferDone() is true. |
5675 |
+ * Since the first write is already dispatched, we'll have to |
5676 |
+ * hack this in somehow. |
5677 |
+ */ |
5678 |
+ if (icap->flags.write_pending) { |
5679 |
+ debug(81, 3) ("icapSendRespMod: oops, write_pending=1\n"); |
5680 |
+ assert(theEnd); |
5681 |
+ return; |
5682 |
+ } |
5683 |
+ if (!cbdataValid(icap)) { |
5684 |
+ debug(81, 3) ("icapSendRespMod: failed to establish connection?\n"); |
5685 |
+ return; |
5686 |
+ } |
5687 |
+ memBufDefInit(&mb); |
5688 |
+ |
5718 |
+ if (icap->sc == 0) { |
5689 |
+ if (icap->sc == 0) { |
5719 |
+ // http connection has been closed without sending us anything |
5690 |
+ // http connection has been closed without sending us anything |
5720 |
+ if (len == 0 && theEnd == 1) { |
5691 |
+ if (icap->respmod.req_hdr_copy.size == 0 && theEnd == 1) { |
5721 |
+ ErrorState *err; |
5692 |
+ ErrorState *err; |
5722 |
+ err = errorCon(ERR_INVALID_RESP, HTTP_BAD_GATEWAY, icap->request); |
5693 |
+ err = errorCon(ERR_INVALID_RESP, HTTP_BAD_GATEWAY, icap->request); |
5723 |
+ errorAppendEntry(icap->respmod.entry, err); |
5694 |
+ errorAppendEntry(icap->respmod.entry, err); |
Lines 5725-5753
Link Here
|
5725 |
+ return; |
5696 |
+ return; |
5726 |
+ } |
5697 |
+ } |
5727 |
+ /* No data sent yet. Start with headers */ |
5698 |
+ /* No data sent yet. Start with headers */ |
5728 |
+ if ((icap->sc = buildRespModHeader(&mb, icap, buf, len, theEnd)) > 0) { |
5699 |
+ icap->sc = buildRespModHeader(&mb, icap); |
5729 |
+ buf += icap->sc; |
5700 |
+ assert(icap->sc != 0); |
5730 |
+ len -= icap->sc; |
|
|
5731 |
+ } |
5732 |
+ /* |
5733 |
+ * Then we do not have http responce headers. All data (previous and those in buf) |
5734 |
+ * now are exist to icap->respmod.req_hdr_copy. Lets get them back....... |
5735 |
+ */ |
5736 |
+ if (icap->sc < 0) { |
5737 |
+ memBufAppend(&icap->respmod.buffer, |
5738 |
+ icap->respmod.req_hdr_copy.buf, |
5739 |
+ icap->respmod.req_hdr_copy.size); |
5740 |
+ icap->sc = icap->respmod.req_hdr_copy.size; |
5741 |
+ icap->respmod.req_hdr_copy.size = 0; |
5742 |
+ buf = NULL; |
5743 |
+ len = 0; |
5744 |
+ } |
5745 |
+ } |
5701 |
+ } |
5746 |
+ if (0 == icap->sc) { |
5702 |
+ if (theEnd) { |
5747 |
+ /* check again; bail if we're not ready to send ICAP/HTTP hdrs */ |
5703 |
+ if (icap->respmod.res_body_sz) |
5748 |
+ debug(81, 5) ("icapSendRespMod: dont have full HTTP response hdrs\n"); |
5704 |
+ icap->flags.send_zero_chunk = 1; |
5749 |
+ memBufClean(&mb); |
5705 |
+ icap->flags.http_server_eof = 1; |
5750 |
+ return; |
|
|
5751 |
+ } |
5706 |
+ } |
5752 |
+#if ICAP_PREVIEW |
5707 |
+#if ICAP_PREVIEW |
5753 |
+ if (preview_size < 0 || !Config.icapcfg.preview_enable) /* preview feature off */ |
5708 |
+ if (preview_size < 0 || !Config.icapcfg.preview_enable) /* preview feature off */ |
Lines 5755-5777
Link Here
|
5755 |
+ |
5710 |
+ |
5756 |
+ if (!icap->flags.preview_done) { |
5711 |
+ if (!icap->flags.preview_done) { |
5757 |
+ /* preview not yet sent */ |
5712 |
+ /* preview not yet sent */ |
5758 |
+ if (icap->sc > 0 && icap->respmod.buffer.size <= preview_size |
|
|
5759 |
+ && len > 0) { |
5760 |
+ /* Try to collect at least preview_size+1 bytes */ |
5761 |
+ /* By collecting one more byte than needed for preview we know best */ |
5762 |
+ /* whether we have to send the ieof chunk extension */ |
5763 |
+ size = icap->respmod.buffer.size + len; |
5764 |
+ if (size > preview_size + 1) |
5765 |
+ size = preview_size + 1; |
5766 |
+ size -= icap->respmod.buffer.size; |
5767 |
+ debug(81, |
5768 |
+ 3) |
5769 |
+ ("icapSendRespMod: FD %d: copy %d more bytes to preview buffer.\n", |
5770 |
+ icap->icap_fd, size); |
5771 |
+ memBufAppend(&icap->respmod.buffer, buf, size); |
5772 |
+ buf = ((char *) buf) + size; |
5773 |
+ len -= size; |
5774 |
+ } |
5775 |
+ if (icap->respmod.buffer.size > preview_size || theEnd) { |
5713 |
+ if (icap->respmod.buffer.size > preview_size || theEnd) { |
5776 |
+ /* we got enough bytes for preview or this is the last call */ |
5714 |
+ /* we got enough bytes for preview or this is the last call */ |
5777 |
+ /* add preview preview now */ |
5715 |
+ /* add preview preview now */ |
Lines 5796-5824
Link Here
|
5796 |
+ /* copy the extra byte and all other data to the icap buffer */ |
5734 |
+ /* copy the extra byte and all other data to the icap buffer */ |
5797 |
+ /* so that it can be handled next time */ |
5735 |
+ /* so that it can be handled next time */ |
5798 |
+ ch = icap->respmod.buffer.buf[preview_size]; |
5736 |
+ ch = icap->respmod.buffer.buf[preview_size]; |
5799 |
+ memBufReset(&icap->respmod.buffer); /* will now be used for other data */ |
5737 |
+ xmemmove(icap->respmod.buffer.buf, |
5800 |
+ memBufAppend(&icap->respmod.buffer, &ch, 1); |
5738 |
+ icap->respmod.buffer.buf + preview_size, |
|
|
5739 |
+ icap->respmod.buffer.size - preview_size); |
5740 |
+ icap->respmod.buffer.size = icap->respmod.buffer.size - preview_size; |
5741 |
+ icap->respmod.buffer.buf[icap->respmod.buffer.size] = '\0'; |
5801 |
+ debug(81, |
5742 |
+ debug(81, |
5802 |
+ 3) |
5743 |
+ 3) |
5803 |
+ ("icapSendRespMod: FD %d: sending preview and keeping %d bytes in internal buf.\n", |
5744 |
+ ("icapSendRespMod: FD %d: sending preview and keeping %d bytes in internal buf.\n", |
5804 |
+ icap->icap_fd, len + 1); |
5745 |
+ icap->icap_fd, icap->respmod.buffer.size); |
5805 |
+ if (len > 0) |
|
|
5806 |
+ memBufAppend(&icap->respmod.buffer, buf, len); |
5807 |
+ } |
5746 |
+ } |
5808 |
+ icap->flags.preview_done = 1; |
5747 |
+ icap->flags.preview_done = 1; |
5809 |
+ icap->flags.wait_for_preview_reply = 1; |
5748 |
+ icap->flags.wait_for_preview_reply = 1; |
5810 |
+ } |
5749 |
+ } |
5811 |
+ } else if (icap->flags.wait_for_preview_reply) { |
5750 |
+ } else if (icap->flags.wait_for_preview_reply) { |
5812 |
+ /* received new data while waiting for preview response */ |
|
|
5813 |
+ /* add data to internal buffer and send later */ |
5814 |
+ debug(81, |
5815 |
+ 3) |
5816 |
+ ("icapSendRespMod: FD %d: add %d more bytes to internal buf while waiting for preview-response.\n", |
5817 |
+ icap->icap_fd, len); |
5818 |
+ if (len > 0) |
5819 |
+ memBufAppend(&icap->respmod.buffer, buf, len); |
5820 |
+ /* do not send any data now while waiting for preview response */ |
5821 |
+ /* but prepare for read more data on the HTTP connection */ |
5822 |
+ memBufClean(&mb); |
5751 |
+ memBufClean(&mb); |
5823 |
+ return; |
5752 |
+ return; |
5824 |
+ } else |
5753 |
+ } else |
Lines 5834-5845
Link Here
|
5834 |
+ icap->sc += icap->respmod.buffer.size; |
5763 |
+ icap->sc += icap->respmod.buffer.size; |
5835 |
+ memBufReset(&icap->respmod.buffer); |
5764 |
+ memBufReset(&icap->respmod.buffer); |
5836 |
+ } |
5765 |
+ } |
5837 |
+ if (len > 0) { |
|
|
5838 |
+ memBufPrintf(&mb, "%x\r\n", len); |
5839 |
+ memBufAppend(&mb, buf, len); |
5840 |
+ memBufAppend(&mb, crlf, 2); |
5841 |
+ icap->sc += len; |
5842 |
+ } |
5843 |
+ if (icap->flags.send_zero_chunk) { |
5766 |
+ if (icap->flags.send_zero_chunk) { |
5844 |
+ /* send zero end chunk */ |
5767 |
+ /* send zero end chunk */ |
5845 |
+ icap->flags.send_zero_chunk = 0; |
5768 |
+ icap->flags.send_zero_chunk = 0; |
Lines 5931-5937
Link Here
|
5931 |
+ * else let http to call icapSendRespMod when new data arrived |
5854 |
+ * else let http to call icapSendRespMod when new data arrived |
5932 |
+ */ |
5855 |
+ */ |
5933 |
+ if (icap->flags.http_server_eof) |
5856 |
+ if (icap->flags.http_server_eof) |
5934 |
+ icapSendRespMod(icap, NULL, 0, 0); |
5857 |
+ icapSendRespMod(icap, 0); |
5935 |
+ /* |
5858 |
+ /* |
5936 |
+ * reset the header to send the rest of the preview |
5859 |
+ * reset the header to send the rest of the preview |
5937 |
+ */ |
5860 |
+ */ |
Lines 6068-6074
Link Here
|
6068 |
+ if (errflag == COMM_ERR_CLOSING) |
5991 |
+ if (errflag == COMM_ERR_CLOSING) |
6069 |
+ return; |
5992 |
+ return; |
6070 |
+ if (errflag) { |
5993 |
+ if (errflag) { |
6071 |
+ if (cbdataValid(icap)) |
5994 |
+ if (cbdataValid(icap)) |
6072 |
+ err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, icap->request); |
5995 |
+ err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, icap->request); |
6073 |
+ else |
5996 |
+ else |
6074 |
+ err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, NULL); |
5997 |
+ err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, NULL); |
Lines 6087-6093
Link Here
|
6087 |
+ debug(81, |
6010 |
+ debug(81, |
6088 |
+ 3) ("icapSendRespModDone: I'm supposed to send zero chunk now\n"); |
6011 |
+ 3) ("icapSendRespModDone: I'm supposed to send zero chunk now\n"); |
6089 |
+ icap->flags.send_zero_chunk = 0; |
6012 |
+ icap->flags.send_zero_chunk = 0; |
6090 |
+ icapSendRespMod(icap, NULL, 0, 1); |
6013 |
+ icapSendRespMod(icap, 1); |
6091 |
+ return; |
6014 |
+ return; |
6092 |
+ } |
6015 |
+ } |
6093 |
+ if (icap->flags.wait_for_preview_reply || icap->flags.wait_for_reply) { |
6016 |
+ if (icap->flags.wait_for_preview_reply || icap->flags.wait_for_reply) { |
Lines 6234-6242
Link Here
|
6234 |
+ return icap->httpState->reply_hdr_state; |
6157 |
+ return icap->httpState->reply_hdr_state; |
6235 |
+} |
6158 |
+} |
6236 |
+ |
6159 |
+ |
6237 |
+static void |
6160 |
+static size_t |
6238 |
+icapProcessHttpReplyHeader(IcapStateData * icap, const char *buf, int size) |
6161 |
+icapProcessHttpReplyHeader(IcapStateData * icap, const char *buf, int size) |
6239 |
+{ |
6162 |
+{ |
|
|
6163 |
+ size_t done; |
6240 |
+ if (NULL == icap->httpState) { |
6164 |
+ if (NULL == icap->httpState) { |
6241 |
+ icap->httpState = cbdataAlloc(HttpStateData); |
6165 |
+ icap->httpState = cbdataAlloc(HttpStateData); |
6242 |
+ icap->httpState->request = requestLink(icap->request); |
6166 |
+ icap->httpState->request = requestLink(icap->request); |
Lines 6244-6252
Link Here
|
6244 |
+ icap->httpState->entry = icap->respmod.entry; |
6168 |
+ icap->httpState->entry = icap->respmod.entry; |
6245 |
+ storeLockObject(icap->httpState->entry); /* lock it */ |
6169 |
+ storeLockObject(icap->httpState->entry); /* lock it */ |
6246 |
+ } |
6170 |
+ } |
6247 |
+ httpProcessReplyHeader(icap->httpState, buf, size); |
6171 |
+ done = httpProcessReplyHeader(icap->httpState, buf, size); |
6248 |
+ if (2 == icap->httpState->reply_hdr_state) |
6172 |
+ if (2 == icap->httpState->reply_hdr_state) |
6249 |
+ EBIT_CLR(icap->httpState->entry->flags, ENTRY_FWD_HDR_WAIT); |
6173 |
+ EBIT_CLR(icap->httpState->entry->flags, ENTRY_FWD_HDR_WAIT); |
|
|
6174 |
+ return done; |
6250 |
+} |
6175 |
+} |
6251 |
+ |
6176 |
+ |
6252 |
+/* |
6177 |
+/* |
Lines 6376-6382
Link Here
|
6376 |
+ } else if (entry->mem_obj->inmem_hi == 0) { |
6301 |
+ } else if (entry->mem_obj->inmem_hi == 0) { |
6377 |
+ ErrorState *err; |
6302 |
+ ErrorState *err; |
6378 |
+ debug(81, 2) ("icapReadReply: FD %d: generating error page\n", fd); |
6303 |
+ debug(81, 2) ("icapReadReply: FD %d: generating error page\n", fd); |
6379 |
+ err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, (request_t *)request); |
6304 |
+ err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, (request_t *) request); |
6380 |
+ err->xerrno = errno; |
6305 |
+ err->xerrno = errno; |
6381 |
+ errorAppendEntry(entry, err); |
6306 |
+ errorAppendEntry(entry, err); |
6382 |
+ comm_close(fd); |
6307 |
+ comm_close(fd); |
Lines 6394-6405
Link Here
|
6394 |
+static int |
6319 |
+static int |
6395 |
+icapReadReply2(IcapStateData * icap) |
6320 |
+icapReadReply2(IcapStateData * icap) |
6396 |
+{ |
6321 |
+{ |
|
|
6322 |
+ size_t done = 0; |
6397 |
+ StoreEntry *entry = icap->respmod.entry; |
6323 |
+ StoreEntry *entry = icap->respmod.entry; |
6398 |
+ const request_t *request = icap->request; |
6324 |
+ const request_t *request = icap->request; |
6399 |
+ debug(81, 3) ("icapReadReply2\n"); |
6325 |
+ debug(81, 3) ("icapReadReply2\n"); |
6400 |
+ if (icap->chunk_buf.size == 0 && entry->mem_obj->inmem_hi == 0) { |
6326 |
+ if (icap->chunk_buf.size == 0 && entry->mem_obj->inmem_hi == 0) { |
6401 |
+ ErrorState *err; |
6327 |
+ ErrorState *err; |
6402 |
+ err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE, (request_t *)request); |
6328 |
+ err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE, (request_t *) request); |
6403 |
+ err->xerrno = errno; |
6329 |
+ err->xerrno = errno; |
6404 |
+ errorAppendEntry(entry, err); |
6330 |
+ errorAppendEntry(entry, err); |
6405 |
+ icap->flags.http_server_eof = 1; |
6331 |
+ icap->flags.http_server_eof = 1; |
Lines 6423-6429
Link Here
|
6423 |
+ debug(81, 3) ("needed=%d\n", needed); |
6349 |
+ debug(81, 3) ("needed=%d\n", needed); |
6424 |
+ assert(needed < 0 || needed >= 0); |
6350 |
+ assert(needed < 0 || needed >= 0); |
6425 |
+ if (0 > expect) { |
6351 |
+ if (0 > expect) { |
6426 |
+ icapProcessHttpReplyHeader(icap, |
6352 |
+ done = icapProcessHttpReplyHeader(icap, |
6427 |
+ icap->chunk_buf.buf, icap->chunk_buf.size); |
6353 |
+ icap->chunk_buf.buf, icap->chunk_buf.size); |
6428 |
+ } else if (0 == expect) { |
6354 |
+ } else if (0 == expect) { |
6429 |
+ /* |
6355 |
+ /* |
Lines 6437-6451
Link Here
|
6437 |
+ icap->respmod.req_hdr_copy.buf, |
6363 |
+ icap->respmod.req_hdr_copy.buf, |
6438 |
+ icap->respmod.req_hdr_copy.size); |
6364 |
+ icap->respmod.req_hdr_copy.size); |
6439 |
+ } |
6365 |
+ } |
6440 |
+ icapProcessHttpReplyHeader(icap, icap->chunk_buf.buf, |
6366 |
+ done = icapProcessHttpReplyHeader(icap, icap->chunk_buf.buf, |
6441 |
+ icap->chunk_buf.size); |
6367 |
+ icap->chunk_buf.size); |
6442 |
+ assert(icapHttpReplyHdrState(icap) == 2); |
6368 |
+ assert(icapHttpReplyHdrState(icap) == 2); |
6443 |
+ icap->chunk_size = 0; /*we are ready to read chunks of data now.... */ |
6369 |
+ icap->chunk_size = 0; /*we are ready to read chunks of data now.... */ |
6444 |
+ } else if (needed) { |
6370 |
+ } else if (needed) { |
6445 |
+ icapProcessHttpReplyHeader(icap, |
6371 |
+ done = icapProcessHttpReplyHeader(icap, |
6446 |
+ icap->chunk_buf.buf, icap->chunk_buf.size); |
6372 |
+ icap->chunk_buf.buf, icap->chunk_buf.size); |
6447 |
+ if (icap->chunk_buf.size >= needed) { |
6373 |
+ if (icap->chunk_buf.size >= needed) { |
6448 |
+ storeAppend(entry, icap->chunk_buf.buf, needed); |
6374 |
+ /*storeAppend not needed here, appended in httpProcessReplyHeader */ |
|
|
6375 |
+ /*must done = so_far - needed */ |
6449 |
+ so_far += needed; |
6376 |
+ so_far += needed; |
6450 |
+ xmemmove(icap->chunk_buf.buf, |
6377 |
+ xmemmove(icap->chunk_buf.buf, |
6451 |
+ icap->chunk_buf.buf + needed, |
6378 |
+ icap->chunk_buf.buf + needed, |
Lines 6473-6480
Link Here
|
6473 |
+ /* data from http.c is not chunked */ |
6400 |
+ /* data from http.c is not chunked */ |
6474 |
+ if (!EBIT_TEST(entry->flags, ENTRY_ABORTED)) { |
6401 |
+ if (!EBIT_TEST(entry->flags, ENTRY_ABORTED)) { |
6475 |
+ debug(81, 3) ("copying %d bytes from chunk_buf to entry\n", |
6402 |
+ debug(81, 3) ("copying %d bytes from chunk_buf to entry\n", |
6476 |
+ icap->chunk_buf.size); |
6403 |
+ icap->chunk_buf.size - done); |
6477 |
+ storeAppend(entry, icap->chunk_buf.buf, icap->chunk_buf.size); |
6404 |
+ if ((icap->chunk_buf.size - done) > 0) |
|
|
6405 |
+ storeAppend(entry, icap->chunk_buf.buf + done, icap->chunk_buf.size - done); |
6478 |
+ icap->chunk_buf.size = 0; |
6406 |
+ icap->chunk_buf.size = 0; |
6479 |
+ } |
6407 |
+ } |
6480 |
+ } else if (2 == icapHttpReplyHdrState(icap)) { |
6408 |
+ } else if (2 == icapHttpReplyHdrState(icap)) { |
Lines 6656-6676
Link Here
|
6656 |
Index: src/protos.h |
6584 |
Index: src/protos.h |
6657 |
=================================================================== |
6585 |
=================================================================== |
6658 |
RCS file: /cvsroot/squid/squid/src/protos.h,v |
6586 |
RCS file: /cvsroot/squid/squid/src/protos.h,v |
6659 |
retrieving revision 1.129 |
6587 |
retrieving revision 1.135 |
6660 |
retrieving revision 1.74.4.11 |
6588 |
retrieving revision 1.74.4.13 |
6661 |
diff -p -u -b -r1.129 -r1.74.4.11 |
6589 |
diff -p -u -b -r1.135 -r1.74.4.13 |
6662 |
--- src/protos.h 23 Oct 2006 11:52:55 -0000 1.129 |
6590 |
--- src/protos.h 26 Feb 2007 09:51:32 -0000 1.135 |
6663 |
+++ src/protos.h 3 Nov 2006 18:47:14 -0000 1.74.4.11 |
6591 |
+++ src/protos.h 27 Feb 2007 21:57:36 -0000 1.74.4.13 |
6664 |
@@ -302,6 +302,8 @@ extern void whoisStart(FwdState *); |
6592 |
@@ -303,6 +303,8 @@ extern void whoisStart(FwdState *); |
6665 |
/* http.c */ |
6593 |
/* http.c */ |
6666 |
extern int httpCachable(method_t); |
6594 |
extern int httpCachable(method_t); |
6667 |
extern void httpStart(FwdState *); |
6595 |
extern void httpStart(FwdState *); |
6668 |
+extern void httpParseReplyHeaders(const char *, http_reply *); |
6596 |
+extern void httpParseReplyHeaders(const char *, http_reply *); |
6669 |
+extern void httpProcessReplyHeader(HttpStateData *, const char *, int); |
6597 |
+extern size_t httpProcessReplyHeader(HttpStateData *, const char *, int); |
6670 |
extern int httpBuildRequestPrefix(request_t * request, |
6598 |
extern int httpBuildRequestPrefix(request_t * request, |
6671 |
request_t * orig_request, |
6599 |
request_t * orig_request, |
6672 |
StoreEntry * entry, |
6600 |
StoreEntry * entry, |
6673 |
@@ -624,6 +626,7 @@ extern void memBufVPrintf(MemBuf * mb, c |
6601 |
@@ -626,6 +628,7 @@ extern void memBufVPrintf(MemBuf * mb, c |
6674 |
extern FREE *memBufFreeFunc(MemBuf * mb); |
6602 |
extern FREE *memBufFreeFunc(MemBuf * mb); |
6675 |
/* puts report on MemBuf _module_ usage into mb */ |
6603 |
/* puts report on MemBuf _module_ usage into mb */ |
6676 |
extern void memBufReport(MemBuf * mb); |
6604 |
extern void memBufReport(MemBuf * mb); |
Lines 6678-6684
Link Here
|
6678 |
|
6606 |
|
6679 |
extern char *mime_get_header(const char *mime, const char *header); |
6607 |
extern char *mime_get_header(const char *mime, const char *header); |
6680 |
extern char *mime_get_header_field(const char *mime, const char *name, const char *prefix); |
6608 |
extern char *mime_get_header_field(const char *mime, const char *name, const char *prefix); |
6681 |
@@ -1417,4 +1420,53 @@ void storeLocateVaryDone(VaryData * data |
6609 |
@@ -1417,4 +1420,55 @@ void storeLocateVaryDone(VaryData * data |
6682 |
void storeLocateVary(StoreEntry * e, int offset, const char *vary_data, String accept_encoding, STLVCB * callback, void *cbdata); |
6610 |
void storeLocateVary(StoreEntry * e, int offset, const char *vary_data, String accept_encoding, STLVCB * callback, void *cbdata); |
6683 |
void storeAddVary(const char *url, const char *log_url, const method_t method, const cache_key * key, const char *etag, const char *vary, const char *vary_headers, const char *accept_encoding); |
6611 |
void storeAddVary(const char *url, const char *log_url, const method_t method, const cache_key * key, const char *etag, const char *vary, const char *vary_headers, const char *accept_encoding); |
6684 |
|
6612 |
|
Lines 6711-6717
Link Here
|
6711 |
+ * icap_respmod.c |
6639 |
+ * icap_respmod.c |
6712 |
+ */ |
6640 |
+ */ |
6713 |
+IcapStateData *icapRespModStart(icap_service_t, request_t *, StoreEntry *, http_state_flags); |
6641 |
+IcapStateData *icapRespModStart(icap_service_t, request_t *, StoreEntry *, http_state_flags); |
6714 |
+void icapSendRespMod(IcapStateData *, char *, int, int); |
6642 |
+void icapSendRespMod(IcapStateData *, int); |
|
|
6643 |
+void icapRespModAddResponceHeaders(IcapStateData *, char *, int); |
6644 |
+void icapRespModAddBodyData(IcapStateData *, char *, int); |
6715 |
+CNCB icapConnectOver; |
6645 |
+CNCB icapConnectOver; |
6716 |
+ |
6646 |
+ |
6717 |
+/* |
6647 |
+/* |
Lines 6838-6848
Link Here
|
6838 |
Index: src/structs.h |
6768 |
Index: src/structs.h |
6839 |
=================================================================== |
6769 |
=================================================================== |
6840 |
RCS file: /cvsroot/squid/squid/src/structs.h,v |
6770 |
RCS file: /cvsroot/squid/squid/src/structs.h,v |
6841 |
retrieving revision 1.136 |
6771 |
retrieving revision 1.141 |
6842 |
retrieving revision 1.81.4.12 |
6772 |
retrieving revision 1.81.4.14 |
6843 |
diff -p -u -b -r1.136 -r1.81.4.12 |
6773 |
diff -p -u -b -r1.141 -r1.81.4.14 |
6844 |
--- src/structs.h 29 Nov 2006 16:52:51 -0000 1.136 |
6774 |
--- src/structs.h 27 Feb 2007 01:16:38 -0000 1.141 |
6845 |
+++ src/structs.h 12 Dec 2006 22:49:47 -0000 1.81.4.12 |
6775 |
+++ src/structs.h 27 Feb 2007 21:57:44 -0000 1.81.4.14 |
6846 |
@@ -423,6 +423,23 @@ struct _RemovalPolicySettings { |
6776 |
@@ -423,6 +423,23 @@ struct _RemovalPolicySettings { |
6847 |
wordlist *args; |
6777 |
wordlist *args; |
6848 |
}; |
6778 |
}; |
Lines 6867-6873
Link Here
|
6867 |
struct _SquidConfig { |
6797 |
struct _SquidConfig { |
6868 |
struct { |
6798 |
struct { |
6869 |
squid_off_t maxSize; |
6799 |
squid_off_t maxSize; |
6870 |
@@ -810,6 +827,9 @@ struct _SquidConfig { |
6800 |
@@ -805,6 +822,9 @@ struct _SquidConfig { |
6871 |
#endif |
6801 |
#endif |
6872 |
time_t refresh_stale_window; |
6802 |
time_t refresh_stale_window; |
6873 |
int umask; |
6803 |
int umask; |
Lines 6877-6883
Link Here
|
6877 |
}; |
6807 |
}; |
6878 |
|
6808 |
|
6879 |
struct _SquidConfig2 { |
6809 |
struct _SquidConfig2 { |
6880 |
@@ -891,6 +911,10 @@ struct _fde { |
6810 |
@@ -887,6 +907,10 @@ struct _fde { |
6881 |
comm_pending write_pending; |
6811 |
comm_pending write_pending; |
6882 |
squid_off_t bytes_read; |
6812 |
squid_off_t bytes_read; |
6883 |
squid_off_t bytes_written; |
6813 |
squid_off_t bytes_written; |
Lines 6888-6895
Link Here
|
6888 |
int uses; /* ie # req's over persistent conn */ |
6818 |
int uses; /* ie # req's over persistent conn */ |
6889 |
struct _fde_disk { |
6819 |
struct _fde_disk { |
6890 |
DWCB *wrt_handle; |
6820 |
DWCB *wrt_handle; |
6891 |
@@ -1095,6 +1119,131 @@ struct _http_state_flags { |
6821 |
@@ -1094,6 +1118,131 @@ struct _http_state_flags { |
6892 |
unsigned int originpeer:1; |
6822 |
unsigned int trailer:1; |
6893 |
}; |
6823 |
}; |
6894 |
|
6824 |
|
6895 |
+#ifdef HS_FEAT_ICAP |
6825 |
+#ifdef HS_FEAT_ICAP |
Lines 7020-7026
Link Here
|
7020 |
struct _HttpStateData { |
6950 |
struct _HttpStateData { |
7021 |
StoreEntry *entry; |
6951 |
StoreEntry *entry; |
7022 |
request_t *request; |
6952 |
request_t *request; |
7023 |
@@ -1106,10 +1255,14 @@ struct _HttpStateData { |
6953 |
@@ -1105,12 +1254,16 @@ struct _HttpStateData { |
7024 |
int fd; |
6954 |
int fd; |
7025 |
http_state_flags flags; |
6955 |
http_state_flags flags; |
7026 |
FwdState *fwd; |
6956 |
FwdState *fwd; |
Lines 7029-7041
Link Here
|
7029 |
+#endif |
6959 |
+#endif |
7030 |
char *body_buf; |
6960 |
char *body_buf; |
7031 |
int body_buf_sz; |
6961 |
int body_buf_sz; |
|
|
6962 |
squid_off_t chunk_size; |
6963 |
String chunkhdr; |
7032 |
}; |
6964 |
}; |
7033 |
|
6965 |
|
7034 |
+ |
6966 |
+ |
7035 |
struct _icpUdpData { |
6967 |
struct _icpUdpData { |
7036 |
struct sockaddr_in address; |
6968 |
struct sockaddr_in address; |
7037 |
void *msg; |
6969 |
void *msg; |
7038 |
@@ -1218,6 +1371,7 @@ struct _clientHttpRequest { |
6970 |
@@ -1219,6 +1372,7 @@ struct _clientHttpRequest { |
7039 |
unsigned int internal:1; |
6971 |
unsigned int internal:1; |
7040 |
unsigned int done_copying:1; |
6972 |
unsigned int done_copying:1; |
7041 |
unsigned int purging:1; |
6973 |
unsigned int purging:1; |
Lines 7043-7049
Link Here
|
7043 |
unsigned int hit:1; |
6975 |
unsigned int hit:1; |
7044 |
} flags; |
6976 |
} flags; |
7045 |
struct { |
6977 |
struct { |
7046 |
@@ -1232,6 +1386,9 @@ struct _clientHttpRequest { |
6978 |
@@ -1233,6 +1387,9 @@ struct _clientHttpRequest { |
7047 |
* zero.. [ahc] |
6979 |
* zero.. [ahc] |
7048 |
*/ |
6980 |
*/ |
7049 |
char readbuf[CLIENT_SOCK_SZ]; |
6981 |
char readbuf[CLIENT_SOCK_SZ]; |
Lines 7053-7059
Link Here
|
7053 |
}; |
6985 |
}; |
7054 |
|
6986 |
|
7055 |
struct _ConnStateData { |
6987 |
struct _ConnStateData { |
7056 |
@@ -1900,6 +2057,9 @@ struct _request_t { |
6988 |
@@ -1901,6 +2058,9 @@ struct _request_t { |
7057 |
unsigned int done_etag:1; /* We have done clientProcessETag on this, don't attempt it again */ |
6989 |
unsigned int done_etag:1; /* We have done clientProcessETag on this, don't attempt it again */ |
7058 |
char *urlgroup; /* urlgroup, returned by redirectors */ |
6990 |
char *urlgroup; /* urlgroup, returned by redirectors */ |
7059 |
char *peer_domain; /* Configured peer forceddomain */ |
6991 |
char *peer_domain; /* Configured peer forceddomain */ |
Lines 7063-7069
Link Here
|
7063 |
BODY_HANDLER *body_reader; |
6995 |
BODY_HANDLER *body_reader; |
7064 |
void *body_reader_data; |
6996 |
void *body_reader_data; |
7065 |
String extacl_log; /* String to be used for access.log purposes */ |
6997 |
String extacl_log; /* String to be used for access.log purposes */ |
7066 |
@@ -2007,7 +2167,11 @@ struct _StatCounters { |
6998 |
@@ -2008,7 +2168,11 @@ struct _StatCounters { |
7067 |
kb_t kbytes_in; |
6999 |
kb_t kbytes_in; |
7068 |
kb_t kbytes_out; |
7000 |
kb_t kbytes_out; |
7069 |
} all , http, ftp, other; |
7001 |
} all , http, ftp, other; |