Join The Works program to have access to the most current content, and to be able to ask questions and get answers from Revelation staff and the Revelation community

At 29 JUN 2022 07:58:21PM Joshua Goddard wrote:

Hi

we have this PHP script in our system that handles incoming web request that are to go to OI. I believe it was created by revelation, but our company has modified it a lot.

Anyway, I am trying to figure out how this PHP script sets the HTTP response code. I can't see anywhere in the code where it does this. Our own OI code also doesn't set it either.

The response code that I get in the browser is 200, so I'm guessing something is setting it to 200 somewhere. Does anyone know? The PHP script is running in a process called "php-cgi.exe".

# OECGI3 to PHP

# OECGI quivalent in PHP

# Note:

# Php can run as isapi service on IIS, PHP can run inprocess

# With TCPIP connection, have socketserver on a separate machine (OI appserver)

# No need for Web server to have user rights on OI appserver

#

# 07-Jun-2007 rjc Created

# 21-Jul-2008 rjc Fix for truncated messages - Receive response in 2k chunks

# 05-Jul-2009 jt Fix for Openinsight default header

# 26-Jun-2010 bzs Converted to OECGI3 functionality

/* configuration processing </QUOTE> —- === At 29 JUN 2022 08:06PM Donald Bakke wrote: === <QUOTE> <QUOTE>Anyway, I am trying to figure out how this PHP script sets the HTTP response code. I can't see anywhere in the code where it does this. Our own OI code also doesn't set it either. </QUOTE> Is your code an INET routine, O4W routine, or something else? Don Bakke SRP Computer Solutions, Inc. </QUOTE> —- === At 29 JUN 2022 09:03PM Joshua Goddard wrote: === <QUOTE>INET </QUOTE> —- === At 29 JUN 2022 09:05PM Joshua Goddard wrote: === <QUOTE>Actually, i am not sure. what's INET? All i know is that there is a java program that starts an OENGNIE, that runs a function called oryx_web_cgi_request, which then returns the request. The data retuned by the OI function does not contain a status code, so it's not being set by OI. </QUOTE> —- === At 29 JUN 2022 09:08PM Joshua Goddard wrote: === <QUOTE>This is the function declaration function oryx_web_cgi_request_mobile(Request, ProcErr) </QUOTE> —- === At 29 JUN 2022 09:11PM Joshua Goddard wrote: === <QUOTE>The function contains Inet_Equates insert, so i think we are "INET". </QUOTE> —- === At 29 JUN 2022 10:06PM bob carten wrote: === <QUOTE> RUN_OEGCGI_REQUEST or INET_FINALIZE might be setting the status code( I don't see it in there at first glance), but I suspect you are correct that the client assumes 200 if it gets a response without a status code. The html protocol might specify that as the default. FWIW, I've written some quasi-restful apis where I needed to follow a specific protocol with specific error codes for different situations In that case I wrote my own handler and specified that handler rather than RUN_OEGCGI_REQUEST. Your Oryx handler may be doing the same thing. In this case my function assembles the response per the HTTP 1.1 specification and returns it as a string. <code> Function RUN_SIMKORKOPOR_API(request) /* Wrapper function to call univrestapi from webserver

05-28-20 rjc clear status on exit

*/

$Insert INET_EQUATES

$insert univ_restapi_statuscodes

$Insert logical

Equ crlf$ To \0D0A\

Declare Function SIMKORKOPOR_API, inet_queryparam

httpmethod= request<request_method$>

url= request<path_Info$>

* accept only a POST request

If httpMethod == "POST" then

apiKey = Inet_QueryParam(request, 'apikey')
If ( apikey != null$ ) Then
  • call the main function, get a JSON response
     json = ""
     resp_code = SIMKORKOPOR_API(request, json)
End else
          isOk = false$
    json = '{"Error":"Authorization key missing"}'
    responseCode = http_stat_Unauthorized$
  end	

End Else

resp_code = http_stat_Not_Implemented$
json = '{"Error":"Not implemented"}'

End

* build the response here, including the status code

response = "HTTP/1.1 ":Oconv(resp_Code, '[HTTP_STATUS_FORMAT]') : CRLF$

Response := "Content-Length: ":len(json) : crlf$

Response := "Content-type: application/json" :CRLF$:CRLF$: json

call Set_Status(0)

Return response

</code>


At 29 JUN 2022 10:22PM bshumsky wrote:

Bob likes rolling "old school", and wants to create his response entirely himself. However, depending on the version of OpenInsight you're running, you should already have an INET_HEADERS insert, and perhaps a series of INETAPI_xxx routines (such as INETAPI_SETCOOKIE, or more relevantly INETAPI_SETSTATUS). By using the provided common elements and/or routines, you allow RUN_OECGI_REQUEST to build the header appropriately, which is where the response code is returned.

In RUN_OECGI_REQUEST, the STATUS header (set via INETAPI_SETSTATUS, or explicitly added to the INET_HEADER_NAMES/INET_HEADER_VALUES arrays with the Inet_Header_Status$ equate) sets the response code. And as you can see in INET_HEADERS, the default status code is indeed 200.

The code to set that, if none other are set, is in RUN_OECGI_REQUEST, and has been in the product since 2009, so it's pretty likely you're running a version that has that in it :-)

So, again, please feel free to set the status to something else if needed, and you can use INETAPI_SETSTATUS to do so…

Hope that helps,

- Bryan Shumsky

Revelation Software, Inc.


At 29 JUN 2022 11:04PM Joshua Goddard wrote:

thanks, that makes sense.

I actually don't want to set the status from oi, i want to set it from php. But being able to set it from OI would help solve a different issue we are having.

I don't know that much about PHP. I could look it up, but perhaps someone knows: how can i set the status from within that oecgi php script?


At 29 JUN 2022 11:32PM Donald Bakke wrote:

thanks, that makes sense.

I actually don't want to set the status from oi, i want to set it from php. But being able to set it from OI would help solve a different issue we are having.

I don't know that much about PHP. I could look it up, but perhaps someone knows: how can i set the status from within that oecgi php script?

OECGIx.php was never designed to set the status, just as OECGIx.exe was never designed to set the status. These are listeners and dispatchers that allow the web server to pass the incoming HTTP request onto the BASIC+ handlers. The BASIC+ handlers are expected to return a fully formed HTTP response, which includes the status, response headers, and the body.

The code that passes the request to the OpenEngine and receives the response should look like this:

$response = SendMessage($sMsg, $PERSISTENT_SOCKET);

I imagine you could add logic to replace the status in $response with something else.

Don Bakke

SRP Computer Solutions, Inc.


At 30 JUN 2022 01:44AM Joshua Goddard wrote:

Sometimes an error occurs within the php script, and it's at that point that I need to set the status to 500.


At 30 JUN 2022 01:54AM Donald Bakke wrote:

Sometimes an error occurs within the php script, and it's at that point that I need to set the status to 500.

Right, because you have a customized version. That makes sense. In that case, then you could construct the entire response yourself.

Don Bakke

SRP Computer Solutions, Inc.


At 30 JUN 2022 08:27AM bob carten wrote:

At 30 JUN 2022 07:17PM Joshua Goddard wrote:

Thanks

http_response_code(503) should work for our situation

View this thread on the Works forum...

  • third_party_content/community/commentary/forums_works/18907344c2fdf346aaba6f4059ffdc46.txt
  • Last modified: 2024/01/04 20:57
  • by 127.0.0.1