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

Function writeResponse

plugins/esi/combo_handler.cc:894–949  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

892static const int GZIP_ENCODING_FIELD_SIZE = sizeof(GZIP_ENCODING_FIELD) - 1;
893
894static bool
895writeResponse(InterceptData &int_data)
896{
897 int_data.setupWrite();
898
899 ByteBlockList body_blocks;
900 string resp_header_fields;
901 prepareResponse(int_data, body_blocks, resp_header_fields);
902
903 int n_bytes_written = 0;
904 if (int_data.creq.status != TS_HTTP_STATUS_OK) {
905 if (!writeErrorResponse(int_data, n_bytes_written)) {
906 LOG_ERROR("Couldn't write response error");
907 return false;
908 }
909 } else {
910 n_bytes_written = OK_REPLY_LINE.size();
911 if (TSIOBufferWrite(int_data.output.buffer, OK_REPLY_LINE.data(), n_bytes_written) == TS_ERROR) {
912 LOG_ERROR("Error while writing reply line");
913 return false;
914 }
915
916 if (!writeStandardHeaderFields(int_data, n_bytes_written)) {
917 LOG_ERROR("Could not write standard header fields");
918 return false;
919 }
920
921 if (resp_header_fields.size()) {
922 if (TSIOBufferWrite(int_data.output.buffer, resp_header_fields.data(), resp_header_fields.size()) == TS_ERROR) {
923 LOG_ERROR("Error while writing additional response header fields");
924 return false;
925 }
926 n_bytes_written += resp_header_fields.size();
927 }
928
929 if (TSIOBufferWrite(int_data.output.buffer, "\r\n", 2) == TS_ERROR) {
930 LOG_ERROR("Error while writing header terminator");
931 return false;
932 }
933 n_bytes_written += 2;
934
935 for (ByteBlockList::iterator iter = body_blocks.begin(); iter != body_blocks.end(); ++iter) {
936 if (TSIOBufferWrite(int_data.output.buffer, iter->data, iter->data_len) == TS_ERROR) {
937 LOG_ERROR("Error while writing content");
938 return false;
939 }
940 n_bytes_written += iter->data_len;
941 }
942 }
943
944 LOG_DEBUG("Wrote reply of size %d", n_bytes_written);
945 TSVIONBytesSet(int_data.output.vio, n_bytes_written);
946
947 TSVIOReenable(int_data.output.vio);
948 return true;
949}
950
951static void

Callers 1

handleServerEventFunction · 0.85

Calls 11

prepareResponseFunction · 0.85
writeErrorResponseFunction · 0.85
TSIOBufferWriteFunction · 0.85
TSVIONBytesSetFunction · 0.85
TSVIOReenableFunction · 0.85
setupWriteMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected