| 45 | static TSMLoc hdr_loc; |
| 46 | |
| 47 | static void |
| 48 | add_header(TSHttpTxn txnp, TSCont contp ATS_UNUSED) |
| 49 | { |
| 50 | TSMBuffer req_bufp; |
| 51 | TSMLoc req_loc; |
| 52 | TSMLoc field_loc; |
| 53 | TSMLoc next_field_loc; |
| 54 | TSMLoc new_field_loc; |
| 55 | int retval; |
| 56 | |
| 57 | if (TSHttpTxnClientReqGet(txnp, &req_bufp, &req_loc) != TS_SUCCESS) { |
| 58 | TSError("[%s] Unable to retrieve client request header", PLUGIN_NAME); |
| 59 | goto done; |
| 60 | } |
| 61 | |
| 62 | field_loc = TSMimeHdrFieldGet(hdr_bufp, hdr_loc, 0); |
| 63 | if (field_loc == TS_NULL_MLOC) { |
| 64 | TSError("[%s] Unable to get field", PLUGIN_NAME); |
| 65 | goto error; |
| 66 | } |
| 67 | |
| 68 | /* Loop on our header containing fields to add */ |
| 69 | while (field_loc) { |
| 70 | /* First create a new field in the client request header */ |
| 71 | if (TSMimeHdrFieldCreate(req_bufp, req_loc, &new_field_loc) != TS_SUCCESS) { |
| 72 | TSError("[%s] Unable to create new field", PLUGIN_NAME); |
| 73 | TSHandleMLocRelease(hdr_bufp, hdr_loc, field_loc); |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | /* Then copy our new field at this new location */ |
| 78 | retval = TSMimeHdrFieldCopy(req_bufp, req_loc, new_field_loc, hdr_bufp, hdr_loc, field_loc); |
| 79 | if (retval == TS_ERROR) { |
| 80 | TSError("[%s] Unable to copy new field", PLUGIN_NAME); |
| 81 | TSHandleMLocRelease(hdr_bufp, hdr_loc, field_loc); |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | /* Add this field to the Http client request header */ |
| 86 | retval = TSMimeHdrFieldAppend(req_bufp, req_loc, new_field_loc); |
| 87 | if (retval != TS_SUCCESS) { |
| 88 | TSError("[%s] Unable to append new field", PLUGIN_NAME); |
| 89 | TSHandleMLocRelease(hdr_bufp, hdr_loc, field_loc); |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | /* We can now release this handle */ |
| 94 | TSHandleMLocRelease(req_bufp, req_loc, new_field_loc); |
| 95 | |
| 96 | next_field_loc = TSMimeHdrFieldNext(hdr_bufp, hdr_loc, field_loc); |
| 97 | TSHandleMLocRelease(hdr_bufp, hdr_loc, field_loc); |
| 98 | field_loc = next_field_loc; |
| 99 | } |
| 100 | |
| 101 | error: |
| 102 | TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); |
| 103 | |
| 104 | done: |
no test coverage detected