<commit_before>/** @file

  ProxyClientTransaction - Base class for protocol client transactions.

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#include "http/HttpSM.h"
#include "http/HttpServerSession.h"
#include "Plugin.h"

#define DebugHttpTxn(fmt, ...) DebugSsn(this, "http_txn", fmt, __VA_ARGS__)

ProxyClientTransaction::ProxyClientTransaction()
  : VConnection(NULL),
    m_active(false),
    parent(NULL),
    current_reader(NULL),
    sm_reader(NULL),
    host_res_style(HOST_RES_NONE),
    restart_immediate(false)
{
}

void
ProxyClientTransaction::new_transaction()
{
  ink_assert(current_reader == NULL);

  // Defensive programming, make sure nothing persists across
  // connection re-use

  ink_release_assert(parent != NULL);
  current_reader = HttpSM::allocate();
  current_reader->init();
  DebugHttpTxn("[%" PRId64 "] Starting transaction %d using sm [%" PRId64 "]", parent->connection_id(),
               parent->get_transact_count(), current_reader->sm_id);

  current_reader->attach_client_session(this, sm_reader);
}

void
ProxyClientTransaction::release(IOBufferReader *r)
{
  ink_assert(current_reader != NULL);

  DebugHttpTxn("[%" PRId64 "] session released by sm [%" PRId64 "]", parent ? parent->connection_id() : 0,
               current_reader ? current_reader->sm_id : 0);

  // current_reader = NULL; // Clear reference to SM

  // Pass along the release to the session
  if (parent) {
    parent->release(this);
  }
}

void
ProxyClientTransaction::attach_server_session(HttpServerSession *ssession, bool transaction_done)
{
  parent->attach_server_session(ssession, transaction_done);
}

void
ProxyClientTransaction::destroy()
{
  if (current_reader) {
    current_reader->ua_session = NULL;
    current_reader             = NULL;
  }
  this->mutex.clear();
}

Action *
ProxyClientTransaction::adjust_thread(Continuation *cont, int event, void *data)
{<commit_msg>TS-4726: Remove unnecessary assert in ProxyClientTransaction::release<commit_after>/** @file

  ProxyClientTransaction - Base class for protocol client transactions.

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#include "http/HttpSM.h"
#include "http/HttpServerSession.h"
#include "Plugin.h"

#define DebugHttpTxn(fmt, ...) DebugSsn(this, "http_txn", fmt, __VA_ARGS__)

ProxyClientTransaction::ProxyClientTransaction()
  : VConnection(NULL),
    m_active(false),
    parent(NULL),
    current_reader(NULL),
    sm_reader(NULL),
    host_res_style(HOST_RES_NONE),
    restart_immediate(false)
{
}

void
ProxyClientTransaction::new_transaction()
{
  ink_assert(current_reader == NULL);

  // Defensive programming, make sure nothing persists across
  // connection re-use

  ink_release_assert(parent != NULL);
  current_reader = HttpSM::allocate();
  current_reader->init();
  DebugHttpTxn("[%" PRId64 "] Starting transaction %d using sm [%" PRId64 "]", parent->connection_id(),
               parent->get_transact_count(), current_reader->sm_id);

  current_reader->attach_client_session(this, sm_reader);
}

void
ProxyClientTransaction::release(IOBufferReader *r)
{
  DebugHttpTxn("[%" PRId64 "] session released by sm [%" PRId64 "]", parent ? parent->connection_id() : 0,
               current_reader ? current_reader->sm_id : 0);

  // Pass along the release to the session
  if (parent) {
    parent->release(this);
  }
}

void
ProxyClientTransaction::attach_server_session(HttpServerSession *ssession, bool transaction_done)
{
  parent->attach_server_session(ssession, transaction_done);
}

void
ProxyClientTransaction::destroy()
{
  if (current_reader) {
    current_reader->ua_session = NULL;
    current_reader             = NULL;
  }
  this->mutex.clear();
}

Action *
ProxyClientTransaction::adjust_thread(Continuation *cont, int event, void *data)
{
{'fraction_non_alphanumeric': 0.09866063006979815, 'fraction_numerical': 0.006036596868515374, 'mean_word_length': 4.437948717948718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5426591', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1494, 'n_words': 461}