IIS and Web Servers
HTTP 4xx Status Code (Configuring the response body)
Gravatar is a globally recognized avatar based on your email address. HTTP 4xx Status Code (Configuring the response body)
  Nau
  All
  May 31, 2023 @ 04:09am

For HTTP status code, the default value is "200 OK" as confirmed in this page and we do get the correct response headers and response body as what we are attempting to return.

However, when changing to 4xx status code, the returned response headers and response body are auto-generated (headers is different and body is empty), so we are not returning what we attempted to return for response headers and response body.

How can we return the 400 HTTP status code with the response headers and response body we want?

Can we configure our own response headers and body when returning 400 status code?

When setting the value to "200 OK":

When setting the value to "400 Bad Request":

Gravatar is a globally recognized avatar based on your email address. re: HTTP 4xx Status Code (Configuring the response body)
  Rick Strahl
  Nau
  May 31, 2023 @ 06:09am

Only for requests that Web Connection handles. Static files won't work because they are not served by Web Connection...

There are ways you can run everything through Web Connection but you wouldn't really want to do that...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HTTP 4xx Status Code (Configuring the response body)
  Nau
  Rick Strahl
  May 31, 2023 @ 07:58am

Hi Rick,

We are currently using Microsoft Windows Server 2016 and IIS 10.

Please see below:

TEXT TO lcResult TEXTMERGE NOSHOW { "locations":[ { "storeNumber": "00000", "status": "Health Signature Error", "technicalMessage": "" } ]
} ENDTEXT

  • with 200 OK, the below response headers and response body is returned

Response.Status = "200 OK" Response.AppendHeader('X-Olo-POS-Spec-Version','1.95')
Response.ContentType=[application/json; charset=utf-8] Response.Write(lcResult)

  • with 400 Bad Request, the below response headers and response body is not returned.

Response.Status = "400 Bad Request" Response.AppendHeader('X-Olo-POS-Spec-Version','1.95')
Response.ContentType=[application/json; charset=utf-8] Response.Write(lcResult)

How can we return the response headers and response body for the 400 Bad Request?

Gravatar is a globally recognized avatar based on your email address. re: HTTP 4xx Status Code (Configuring the response body)
  Rick Strahl
  Nau
  May 31, 2023 @ 09:30am

Hmmm... that works for me:

For this code:

FUNCTION  SetCookie()

Response.Status = "400 Bad Request"

Response.AppendHeader("Bogus", "123123123123")
Response.AddCookie("TestValue","Time " + TIME())

Response.ContentType="text/plain"
Response.Write("Cookie Set")
ENDFUNC
*  SetCookie

There are settings in IIS and your browser that can override how non-200 responses are returned. Web Connection default config turns those off by default but if you muck with the settings or don't set them you might get different behavior. It's not because Web Connection is not sending them but because IIS is intercepting and handling the errors instead.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: HTTP 4xx Status Code (Configuring the response body)
  Nau
  Rick Strahl
  May 31, 2023 @ 10:18am

Hi Rick,

Thank you for your reply! I appreciate it.

I managed to get it working by looking at this link.

Gravatar is a globally recognized avatar based on your email address. re: HTTP 4xx Status Code (Configuring the response body)
  Rick Strahl
  Nau
  Jun 1, 2023 @ 05:43am

If that worked most likely you are running the old ISAPI extension, not the .NET one. The .NET module takes over error handling for all requests that run through Web Connection and you should always get the output that you send.

ISAPI didn't have support for that so it can only be set at the server level.

+++ Rick ---

© 1996-2024