////////////////////////////////////////////////////////////////////// Set a header to a specific value. This will avoid going to through a remove / add sequence in case of an existing header. but clean.
| 798 | // remove / add sequence in case of an existing header. |
| 799 | // but clean. |
| 800 | bool |
| 801 | S3Request::set_header(const char *header, int header_len, const char *val, int val_len) |
| 802 | { |
| 803 | if (!header || header_len <= 0 || !val || val_len <= 0) { |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | bool ret = false; |
| 808 | TSMLoc field_loc = TSMimeHdrFieldFind(_bufp, _hdr_loc, header, header_len); |
| 809 | |
| 810 | if (!field_loc) { |
| 811 | // No existing header, so create one |
| 812 | if (TS_SUCCESS == TSMimeHdrFieldCreateNamed(_bufp, _hdr_loc, header, header_len, &field_loc)) { |
| 813 | if (TS_SUCCESS == TSMimeHdrFieldValueStringSet(_bufp, _hdr_loc, field_loc, -1, val, val_len)) { |
| 814 | TSMimeHdrFieldAppend(_bufp, _hdr_loc, field_loc); |
| 815 | ret = true; |
| 816 | } |
| 817 | TSHandleMLocRelease(_bufp, _hdr_loc, field_loc); |
| 818 | } |
| 819 | } else { |
| 820 | TSMLoc tmp = nullptr; |
| 821 | bool first = true; |
| 822 | |
| 823 | while (field_loc) { |
| 824 | tmp = TSMimeHdrFieldNextDup(_bufp, _hdr_loc, field_loc); |
| 825 | if (first) { |
| 826 | first = false; |
| 827 | if (TS_SUCCESS == TSMimeHdrFieldValueStringSet(_bufp, _hdr_loc, field_loc, -1, val, val_len)) { |
| 828 | ret = true; |
| 829 | } |
| 830 | } else { |
| 831 | TSMimeHdrFieldDestroy(_bufp, _hdr_loc, field_loc); |
| 832 | } |
| 833 | TSHandleMLocRelease(_bufp, _hdr_loc, field_loc); |
| 834 | field_loc = tmp; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | if (ret) { |
| 839 | Dbg(dbg_ctl, "Set the header %.*s: %.*s", header_len, header, val_len, val); |
| 840 | } |
| 841 | |
| 842 | return ret; |
| 843 | } |
| 844 | |
| 845 | // dst points to starting offset of dst buffer |
| 846 | // dst_len remaining space in buffer |
no test coverage detected