Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI_Get_Callback should provide the HTTP status code #238

Open
hemebond opened this issue Jan 4, 2025 · 4 comments
Open

URI_Get_Callback should provide the HTTP status code #238

hemebond opened this issue Jan 4, 2025 · 4 comments

Comments

@hemebond
Copy link
Contributor

hemebond commented Jan 4, 2025

When using a web API, the HTTP status code is used to indicate the state of requests. Without this status code the client can't determine what to do next, e.g., re-sending the request, or showing an error to the players.

This behaviour also differs from FTEQW which does provide the HTTP status code, e.g.:

got response from URL request
Request ID: 1
Response code: 201
Response body: {"name":"3qyH9wNUhLo","status":4}

The help text in the dpextensions.qc actually says it should be returning an HTTP code:

//the following callback will receive the data and MUST exist!
//  void(float id, float status, string data) URI_Get_Callback;
//status is either
//  negative for an internal error,
//  0 for success, or
//  the HTTP response code on server error (e.g. 404)
@divVerent
Copy link
Contributor

divVerent commented Jan 5, 2025

The extension actually says it should return 0 for success, and all 2xx and 3xx codes are success. This is important as QC code is expected to use != 0 to check for success in the return value.

I suggest providing a way for the caller to specify how non-200 success statuses should be handled (maybe some kind of flag to enable exposing the non-2xx success status?).

@hemebond
Copy link
Contributor Author

hemebond commented Jan 5, 2025

You're right. I thought it also wasn't returning the HTTP status code for 404, because other errors were just giving me a -1, but it does show a 404. A flag sounds good.

@divVerent
Copy link
Contributor

The alternative is changing the extension to only map 200 to 0, which may be OK to do.

But for that we first need to survey which other mods exist that use this, and if they would break from this.

@hemebond
Copy link
Contributor Author

hemebond commented Jan 6, 2025

I think a flag that completely switches to HTTP status codes would be fine. I don't think the engine should be deciding what is a success or failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants