1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #pragma once 20 21 #include "ats_fcgi_client.h" 22 #include "fcgi_config.h" 23 #include "atscppapi/Transaction.h" 24 #include "atscppapi/TransactionPlugin.h" 25 #include "ts/ink_defs.h" 26 #include "ts/ts.h" 27 #include "utils_internal.h" 28 #include <atscppapi/Headers.h> 29 #include <atscppapi/InterceptPlugin.h> 30 #include <atscppapi/utils.h> 31 #include <iostream> 32 #include <iterator> 33 #include <map> 34 #include <netinet/in.h> 35 #include <string.h> 36 37 #define PORT 60000 38 39 using std::cout; 40 using std::endl; 41 using std::string; 42 43 using namespace atscppapi; 44 45 namespace ats_plugin 46 { 47 class ServerConnection; 48 class ServerIntercept : public InterceptPlugin 49 { 50 public: 51 int headCount = 0, bodyCount = 0, emptyCount = 0; 52 bool dataBuffered, clientAborted = false; 53 bool serverDataBuffered; 54 string serverResponse; 55 TSHttpTxn _txn; ServerIntercept(Transaction & transaction)56 ServerIntercept(Transaction &transaction) : InterceptPlugin(transaction, InterceptPlugin::SERVER_INTERCEPT) 57 { 58 _txn = static_cast<TSHttpTxn>(transaction.getAtsHandle()); 59 clientAborted = false; 60 dataBuffered = false; 61 serverDataBuffered = false; 62 inputCompleteState = false; 63 outputCompleteState = false; 64 TSDebug(PLUGIN_NAME, "ServerIntercept : Added Server intercept"); 65 } 66 67 ~ServerIntercept() override; 68 69 void consume(const string &data, InterceptPlugin::RequestDataType type) override; 70 void handleInputComplete() override; 71 void streamReqHeader(const string &data); 72 void streamReqBody(const string &data); 73 74 bool writeResponseChunkToATS(std::string &data); 75 bool setResponseOutputComplete(); 76 77 void setRequestId(uint request_id)78 setRequestId(uint request_id) 79 { 80 _request_id = request_id; 81 } 82 83 uint requestId()84 requestId() 85 { 86 return _request_id; 87 } 88 89 bool getOutputCompleteState()90 getOutputCompleteState() 91 { 92 return outputCompleteState; 93 } 94 95 private: 96 uint _request_id; 97 string clientHeader, clientBody; 98 99 bool inputCompleteState, outputCompleteState; 100 }; 101 } // namespace ats_plugin 102