~ubuntu-branches/ubuntu/utopic/cntlm/utopic

« back to all changes in this revision

Viewing changes to http.c

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2012-08-01 23:04:45 UTC
  • Revision ID: package-import@ubuntu.com-20120801230445-rt2sof77bvdluzcv
Tags: 0.92.3-1ubuntu1
Cherry-pick r306 from 0.93 to properly handle non-HTTP/1.1 keep-alive
(LP: #1009436)

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 */
85
85
int headers_recv(int fd, rr_data_t data) {
86
86
        int i, bsize;
87
 
        int len;
 
87
        int len, is_http = 0;
88
88
        char *buf;
89
89
        char *tok, *s3 = 0;
90
90
        char *orig = NULL;
108
108
        orig = strdup(buf);
109
109
        len = strlen(buf);
110
110
        tok = strtok_r(buf, " ", &s3);
111
 
        if (tok && (!strncasecmp(buf, "HTTP/", 5) || !strncasecmp(tok, "ICY", 3))) {
 
111
        if (tok && ((is_http = !strncasecmp(tok, "HTTP/", 5)) || !strncasecmp(tok, "ICY", 3))) {
112
112
                data->req = 0;
113
113
                data->empty = 0;
114
114
                data->http = strdup(tok);
115
115
                data->msg = NULL;
116
116
 
 
117
                /*
 
118
                 * Let's find out the numeric version of the HTTP version: 09, 10, 11.
 
119
                 * Set to -1 if header is misformatted.
 
120
                 */
 
121
                if (is_http && (tok = strchr(data->http, '/')) && strlen(tok) >= 4 && isdigit(tok[1]) && isdigit(tok[3])) {
 
122
                        data->http_version = (tok[1] - 0x30) * 10 + (tok[3] - 0x30);
 
123
                } else {
 
124
                        data->http_version = -1;
 
125
                }
 
126
 
117
127
                tok = strtok_r(NULL, " ", &s3);
118
128
                if (tok) {
119
129
                        ccode = strdup(tok);
156
166
                        goto bailout;
157
167
                }
158
168
 
 
169
                /*
 
170
                 * Let's find out the numeric version of the HTTP version: 09, 10, 11.
 
171
                 * Set to -1 if header is misformatted.
 
172
                 */
 
173
                if ((tok = strchr(data->http, '/')) && strlen(tok) >= 4 && isdigit(tok[1]) && isdigit(tok[3])) {
 
174
                        data->http_version = (tok[1] - 0x30) * 10 + (tok[3] - 0x30);
 
175
                } else {
 
176
                        data->http_version = -1;
 
177
                }
 
178
 
159
179
                if ((tok = strstr(data->url, "://"))) {
160
180
                        tok += 3;
161
181
                } else {