MCPcopy Create free account
hub / github.com/apache/trafficserver / WriteResponseHeader

Function WriteResponseHeader

plugins/statichit/statichit.cc:300–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300static TSReturnCode
301WriteResponseHeader(StaticHitRequest *trq, TSHttpStatus status)
302{
303 StaticHitHttpHeader response;
304
305 VDEBUG("writing response header");
306
307 if (TSHttpHdrTypeSet(response.buffer, response.header, TS_HTTP_TYPE_RESPONSE) != TS_SUCCESS) {
308 VERROR("failed to set type");
309 return TS_ERROR;
310 }
311 if (TSHttpHdrVersionSet(response.buffer, response.header, TS_HTTP_VERSION(1, 1)) != TS_SUCCESS) {
312 VERROR("failed to set HTTP version");
313 return TS_ERROR;
314 }
315 if (TSHttpHdrStatusSet(response.buffer, response.header, status) != TS_SUCCESS) {
316 VERROR("failed to set HTTP status");
317 return TS_ERROR;
318 }
319
320 TSHttpHdrReasonSet(response.buffer, response.header, TSHttpHdrReasonLookup(status), -1);
321
322 if (status == TS_HTTP_STATUS_OK) {
323 // Set the Content-Length header.
324 HeaderFieldIntSet(response, TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH, trq->nbytes);
325
326 // Set the Cache-Control header.
327 if (trq->maxAge > 0) {
328 char buf[64];
329
330 snprintf(buf, sizeof(buf), "max-age=%u", trq->maxAge);
331 HeaderFieldStringSet(response, TS_MIME_FIELD_CACHE_CONTROL, TS_MIME_LEN_CACHE_CONTROL, buf);
332 HeaderFieldDateSet(response, TS_MIME_FIELD_LAST_MODIFIED, TS_MIME_LEN_LAST_MODIFIED, time(nullptr));
333
334 } else {
335 HeaderFieldStringSet(response, TS_MIME_FIELD_CACHE_CONTROL, TS_MIME_LEN_CACHE_CONTROL, "no-cache");
336 }
337
338 HeaderFieldStringSet(response, TS_MIME_FIELD_CONTENT_TYPE, TS_MIME_LEN_CONTENT_TYPE, trq->mimeType.c_str());
339 }
340
341 // Write the header to the IO buffer. Set the VIO bytes so that we can get a WRITE_COMPLETE
342 // event when this is done.
343 int hdrlen = TSHttpHdrLengthGet(response.buffer, response.header);
344
345 TSHttpHdrPrint(response.buffer, response.header, trq->writeio.iobuf);
346 TSVIONBytesSet(trq->writeio.vio, hdrlen);
347 TSVIOReenable(trq->writeio.vio);
348
349 TSStatIntIncrement(StatCountBytes, hdrlen);
350
351 return TS_SUCCESS;
352}
353
354static bool
355StaticHitParseRequest(StaticHitRequest *trq)

Callers 1

StaticHitInterceptHookFunction · 0.70

Calls 14

TSHttpHdrTypeSetFunction · 0.85
TSHttpHdrVersionSetFunction · 0.85
TSHttpHdrStatusSetFunction · 0.85
TSHttpHdrReasonSetFunction · 0.85
TSHttpHdrReasonLookupFunction · 0.85
TSHttpHdrLengthGetFunction · 0.85
TSHttpHdrPrintFunction · 0.85
TSVIONBytesSetFunction · 0.85
TSVIOReenableFunction · 0.85
TSStatIntIncrementFunction · 0.85
HeaderFieldIntSetFunction · 0.70
HeaderFieldStringSetFunction · 0.70

Tested by

no test coverage detected