1 /** @file 2 3 A brief file description 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 #pragma once 25 26 #include "HttpSM.h" 27 28 class TransformVConnection; 29 30 class TransformTerminus : public VConnection 31 { 32 public: 33 TransformTerminus(TransformVConnection *tvc); 34 35 int handle_event(int event, void *edata); 36 37 VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) override; 38 VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false) override; 39 void do_io_close(int lerrno = -1) override; 40 void do_io_shutdown(ShutdownHowTo_t howto) override; 41 42 void reenable(VIO *vio) override; 43 44 public: 45 TransformVConnection *m_tvc; 46 VIO m_read_vio; 47 VIO m_write_vio; 48 int m_event_count; 49 int m_deletable; 50 int m_closed; 51 int m_called_user; 52 }; 53 54 class TransformVConnection : public TransformVCChain 55 { 56 public: 57 TransformVConnection(Continuation *cont, APIHook *hooks); 58 ~TransformVConnection() override; 59 60 int handle_event(int event, void *edata); 61 62 VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) override; 63 VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false) override; 64 void do_io_close(int lerrno = -1) override; 65 void do_io_shutdown(ShutdownHowTo_t howto) override; 66 67 void reenable(VIO *vio) override; 68 69 /** Compute the backlog. 70 @return The actual backlog, or a value at least @a limit. 71 */ 72 uint64_t backlog(uint64_t limit = UINT64_MAX) override; 73 74 public: 75 VConnection *m_transform; 76 Continuation *m_cont; 77 TransformTerminus m_terminus; 78 int m_closed; 79 }; 80 81 class TransformControl : public Continuation 82 { 83 public: 84 TransformControl(); 85 86 int handle_event(int event, void *edata); 87 88 public: 89 APIHooks m_hooks; 90 VConnection *m_tvc = nullptr; 91 IOBufferReader *m_read_buf = nullptr; 92 MIOBuffer *m_write_buf = nullptr; 93 }; 94 95 class NullTransform : public INKVConnInternal 96 { 97 public: 98 NullTransform(ProxyMutex *mutex); 99 ~NullTransform() override; 100 101 int handle_event(int event, void *edata); 102 103 public: 104 MIOBuffer *m_output_buf; 105 IOBufferReader *m_output_reader; 106 VIO *m_output_vio; 107 }; 108 109 class RangeTransform : public INKVConnInternal 110 { 111 public: 112 RangeTransform(ProxyMutex *mutex, RangeRecord *ranges, int num_fields, HTTPHdr *transform_resp, const char *content_type, 113 int content_type_len, int64_t content_length); 114 ~RangeTransform() override; 115 116 int handle_event(int event, void *edata); 117 118 void transform_to_range(); 119 void add_boundary(bool end); 120 void add_sub_header(int index); 121 void change_response_header(); 122 void calculate_output_cl(); 123 124 public: 125 MIOBuffer *m_output_buf; 126 IOBufferReader *m_output_reader; 127 128 HTTPHdr *m_transform_resp; 129 VIO *m_output_vio; 130 int64_t m_range_content_length; 131 int m_num_chars_for_cl; 132 int m_num_range_fields; 133 int m_current_range; 134 const char *m_content_type; 135 int m_content_type_len; 136 RangeRecord *m_ranges; 137 int64_t m_output_cl; 138 int64_t m_done; 139 }; 140