| 103 | } |
| 104 | |
| 105 | void |
| 106 | DoRemap(const Instance &i, TSHttpTxn t) |
| 107 | { |
| 108 | assert(t != nullptr); |
| 109 | /* |
| 110 | if (POST || PUT) { |
| 111 | transformRequest |
| 112 | } |
| 113 | */ |
| 114 | TSMBuffer buffer; |
| 115 | TSMLoc location; |
| 116 | |
| 117 | CHECK(TSHttpTxnClientReqGet(t, &buffer, &location)); |
| 118 | |
| 119 | assert(buffer != nullptr); |
| 120 | assert(location != nullptr); |
| 121 | |
| 122 | int method_length; |
| 123 | const char *const method = TSHttpHdrMethodGet(buffer, location, &method_length); |
| 124 | |
| 125 | Dbg(dbg_ctl, "Method is %s.", std::string(method, method_length).c_str()); |
| 126 | |
| 127 | // A value of -1 is used to indicate there was no Content-Length header. |
| 128 | int content_length = -1; |
| 129 | // Retrieve the value of the Content-Length header. |
| 130 | auto field_loc = TSMimeHdrFieldFind(buffer, location, TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH); |
| 131 | if (field_loc != TS_NULL_MLOC) { |
| 132 | content_length = TSMimeHdrFieldValueUintGet(buffer, location, field_loc, -1); |
| 133 | TSHandleMLocRelease(buffer, location, field_loc); |
| 134 | } |
| 135 | bool const is_post_or_put = (method_length == TS_HTTP_LEN_POST && memcmp(TS_HTTP_METHOD_POST, method, TS_HTTP_LEN_POST) == 0) || |
| 136 | (method_length == TS_HTTP_LEN_PUT && memcmp(TS_HTTP_METHOD_PUT, method, TS_HTTP_LEN_PUT) == 0); |
| 137 | if (i.skipPostPut && is_post_or_put) { |
| 138 | Dbg(dbg_ctl, "skip_post_put: skipping a POST or PUT request."); |
| 139 | } else if (content_length < 0 && is_post_or_put) { |
| 140 | // HttpSM would need an update for POST request transforms to support |
| 141 | // chunked request bodies. It currently does not support this. |
| 142 | Dbg(dbg_ctl, "Skipping a non-Content-Length POST or PUT request."); |
| 143 | } else { |
| 144 | { |
| 145 | TSMLoc field; |
| 146 | |
| 147 | CHECK(TSMimeHdrFieldCreateNamed(buffer, location, "X-Multiplexer", 13, &field)); |
| 148 | assert(field != nullptr); |
| 149 | |
| 150 | CHECK(TSMimeHdrFieldValueStringSet(buffer, location, field, -1, "original", 8)); |
| 151 | |
| 152 | CHECK(TSMimeHdrFieldAppend(buffer, location, field)); |
| 153 | |
| 154 | CHECK(TSHandleMLocRelease(buffer, location, field)); |
| 155 | } |
| 156 | |
| 157 | Requests requests; |
| 158 | generateRequests(i.origins, buffer, location, requests); |
| 159 | assert(requests.size() == i.origins.size()); |
| 160 | |
| 161 | if (is_post_or_put || content_length > 0) { |
| 162 | const TSVConn vconnection = TSTransformCreate(handlePost, t); |
no test coverage detected