src/server/daemon/http.c

changeset 385
a1f4cb076d2f
parent 345
5832e10fc59a
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
196 } 196 }
197 197
198 198
199 /* ---------------------------- http_set_finfo ---------------------------- */ 199 /* ---------------------------- http_set_finfo ---------------------------- */
200 200
201 static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime) 201 static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime, const char *etag)
202 { 202 {
203 struct tm mtms; 203 struct tm mtms;
204 struct tm *mtm = system_gmtime(&mtime, &mtms); 204 struct tm *mtm = system_gmtime(&mtime, &mtms);
205 pb_param *pp; 205 pb_param *pp;
206 206
221 if (!pp || !pp->value) 221 if (!pp || !pp->value)
222 return REQ_ABORTED; 222 return REQ_ABORTED;
223 snprintf(pp->value, content_length_size, "%lld", (long long)size); 223 snprintf(pp->value, content_length_size, "%lld", (long long)size);
224 pblock_kpinsert(pb_key_content_length, pp, rq->srvhdrs); 224 pblock_kpinsert(pb_key_content_length, pp, rq->srvhdrs);
225 225
226 char *etag;
227 if (http_etag) { 226 if (http_etag) {
228 /* Insert Etag */ 227 /* Insert Etag */
229 pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG); 228 if(etag) {
230 if (!pp || !pp->value) 229 pblock_kvinsert(pb_key_etag, etag, strlen(etag), rq->srvhdrs);
231 return REQ_ABORTED; 230 } else {
232 http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime); 231 pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG);
233 pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs); 232 if (!pp || !pp->value)
234 etag = pp->value; 233 return REQ_ABORTED;
234 http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime);
235 pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs);
236 etag = pp->value;
237 }
238
235 } else { 239 } else {
236 etag = NULL; 240 etag = NULL;
237 } 241 }
238 242
239 /* Check If-modified-since, etc. */ 243 /* Check If-modified-since, etc. */
240 return http_check_preconditions(sn, rq, mtm, etag); 244 return http_check_preconditions(sn, rq, mtm, etag);
241 } 245 }
242 246
243 NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo) 247 NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo)
244 { 248 {
245 return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime); 249 return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime, NULL);
250 }
251
252 NSAPI_PUBLIC int http_set_finfo_etag(Session *sn, Request *rq, struct stat *finfo, const char *etag) {
253 return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime, etag);
246 } 254 }
247 255
248 256
249 /* ---------------------------- http_hdrs2env ----------------------------- */ 257 /* ---------------------------- http_hdrs2env ----------------------------- */
250 258

mercurial