example/thread-pool/psi.c
static int
transformable(INKHttpTxn txnp)
{
  /*  We are only interested in transforming "200 OK" responses
     with a Content-Type: text/ header and with X-Psi header */
  INKMBuffer bufp;
  INKMLoc hdr_loc, field_loc;
  INKHttpStatus resp_status;
  const char *value;

  INKHttpTxnServerRespGet(txnp, &bufp, &hdr_loc);

  resp_status = INKHttpHdrStatusGet(bufp, hdr_loc);
  if (resp_status == INK_ERROR) {
    INKError("[transformable] Error while getting http status");
  }
  if ((resp_status == INK_ERROR) || (resp_status != INK_HTTP_STATUS_OK)) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }

  field_loc = INKMimeHdrFieldFind(bufp, hdr_loc, INK_MIME_FIELD_CONTENT_TYPE, -1);
  if (field_loc == INK_ERROR_PTR) {
    INKError("[transformable] Error while searching Content-Type field");
  }
  if ((field_loc == INK_ERROR_PTR) || (field_loc == NULL)) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }

  value = INKMimeHdrFieldValueGet(bufp, hdr_loc, field_loc, 0, NULL);
  if (value == INK_ERROR_PTR) {
    INKError("[transformable] Error while getting Content-Type field value");
  }
  if ((value == INK_ERROR_PTR) || (value == NULL) || (strncasecmp(value, "text/", sizeof("text/") - 1) != 0)) {
    INKHandleMLocRelease(bufp, hdr_loc, field_loc);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }

  INKHandleMLocRelease(bufp, hdr_loc, field_loc);

  field_loc = INKMimeHdrFieldFind(bufp, hdr_loc, MIME_FIELD_XPSI, -1);
  if (value == INK_ERROR_PTR) {
    INKError("[transformable] Error while searching XPSI field");
  }
  if ((value == INK_ERROR_PTR) || (field_loc == NULL)) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }

  INKHandleMLocRelease(bufp, hdr_loc, field_loc);
  INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);

  return 1;
}
/*-------------------------------------------------------------------------
  transformable
  Determine if the current transaction should be transformed or not

  Input:
    txnp      current transaction
  Output :
  Return Value:
    1  if transformable
    0  if not
  -------------------------------------------------------------------------*/
transformable
Determine if the current transaction should be transformed or not

txnp      current transaction
Output :
Return Value:
1  if transformable
0  if not
transformable Determine if the current transaction should be transformed or not txnp current transaction Output : Return Value : 1 if transformable 0 if not
static int
transformable(INKHttpTxn txnp)
{
  INKMBuffer bufp;
  INKMLoc hdr_loc, field_loc;
  INKHttpStatus resp_status;
  const char *value;
  INKHttpTxnServerRespGet(txnp, &bufp, &hdr_loc);
  resp_status = INKHttpHdrStatusGet(bufp, hdr_loc);
  if (resp_status == INK_ERROR) {
    INKError("[transformable] Error while getting http status");
  }
  if ((resp_status == INK_ERROR) || (resp_status != INK_HTTP_STATUS_OK)) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }
  field_loc = INKMimeHdrFieldFind(bufp, hdr_loc, INK_MIME_FIELD_CONTENT_TYPE, -1);
  if (field_loc == INK_ERROR_PTR) {
    INKError("[transformable] Error while searching Content-Type field");
  }
  if ((field_loc == INK_ERROR_PTR) || (field_loc == NULL)) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }
  value = INKMimeHdrFieldValueGet(bufp, hdr_loc, field_loc, 0, NULL);
  if (value == INK_ERROR_PTR) {
    INKError("[transformable] Error while getting Content-Type field value");
  }
  if ((value == INK_ERROR_PTR) || (value == NULL) || (strncasecmp(value, "text/", sizeof("text/") - 1) != 0)) {
    INKHandleMLocRelease(bufp, hdr_loc, field_loc);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }
  INKHandleMLocRelease(bufp, hdr_loc, field_loc);
  field_loc = INKMimeHdrFieldFind(bufp, hdr_loc, MIME_FIELD_XPSI, -1);
  if (value == INK_ERROR_PTR) {
    INKError("[transformable] Error while searching XPSI field");
  }
  if ((value == INK_ERROR_PTR) || (field_loc == NULL)) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    return 0;
  }
  INKHandleMLocRelease(bufp, hdr_loc, field_loc);
  INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
  return 1;
}
static int transformable ( INKHttpTxn txnp ) { INKMBuffer bufp ; INKMLoc hdr_loc , field_loc ; INKHttpStatus resp_status ; const char * value ; INKHttpTxnServerRespGet ( txnp , & bufp , & hdr_loc ) ; resp_status = INKHttpHdrStatusGet ( bufp , hdr_loc ) ; if ( resp_status == INK_ERROR ) { INKError ( " " ) ; } if ( ( resp_status == INK_ERROR ) || ( resp_status != INK_HTTP_STATUS_OK ) ) { INKHandleMLocRelease ( bufp , INK_NULL_MLOC , hdr_loc ) ; return 0 ; } field_loc = INKMimeHdrFieldFind ( bufp , hdr_loc , INK_MIME_FIELD_CONTENT_TYPE , -1 ) ; if ( field_loc == INK_ERROR_PTR ) { INKError ( " " ) ; } if ( ( field_loc == INK_ERROR_PTR ) || ( field_loc == NULL ) ) { INKHandleMLocRelease ( bufp , INK_NULL_MLOC , hdr_loc ) ; return 0 ; } value = INKMimeHdrFieldValueGet ( bufp , hdr_loc , field_loc , 0 , NULL ) ; if ( value == INK_ERROR_PTR ) { INKError ( " " ) ; } if ( ( value == INK_ERROR_PTR ) || ( value == NULL ) || ( strncasecmp ( value , " " , sizeof ( " " ) - 1 ) != 0 ) ) { INKHandleMLocRelease ( bufp , hdr_loc , field_loc ) ; INKHandleMLocRelease ( bufp , INK_NULL_MLOC , hdr_loc ) ; return 0 ; } INKHandleMLocRelease ( bufp , hdr_loc , field_loc ) ; field_loc = INKMimeHdrFieldFind ( bufp , hdr_loc , MIME_FIELD_XPSI , -1 ) ; if ( value == INK_ERROR_PTR ) { INKError ( " " ) ; } if ( ( value == INK_ERROR_PTR ) || ( field_loc == NULL ) ) { INKHandleMLocRelease ( bufp , INK_NULL_MLOC , hdr_loc ) ; return 0 ; } INKHandleMLocRelease ( bufp , hdr_loc , field_loc ) ; INKHandleMLocRelease ( bufp , INK_NULL_MLOC , hdr_loc ) ; return 1 ; }
transformable
Determine if the current transaction should be transformed or not
transformable Determine if the current transaction should be transformed or not
/*  We are only interested in transforming "200 OK" responses
     with a Content-Type: text/ header and with X-Psi header */