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

CPL/HTTP: Include Response Code in CPLHTTPResult. #10874

Open
SpencerDWallace opened this issue Sep 25, 2024 · 2 comments
Open

CPL/HTTP: Include Response Code in CPLHTTPResult. #10874

SpencerDWallace opened this issue Sep 25, 2024 · 2 comments

Comments

@SpencerDWallace
Copy link

Feature description

APIs may use HTTP response codes to distinguish errors with the request. Currently, the caller of CPLHTTPFetch (and similar) is unable to retrieve the HTTP response code. I would request that a field for the response code is added to CPLHTTPResult.

Additional context

I could work on this if the feature is acceptable

@jratike80
Copy link
Collaborator

Test with a not-existing OGC API Features collection and ogrinfo shows HTTP code for me

ERROR 1: HTTP error code : 404
ERROR 1: {
  "code" : "404",
  "description" : "Exception occurred"
}
ogrinfo failed - unable to open 'oapif:https://....

With configuration option --config cpl_curl_verbose on much more info about the http traffic is shown. So perhaps the information that you want is already available, but in some other way.

@rouault
Copy link
Member

rouault commented Sep 26, 2024

I would request that a field for the response code is added to CPLHTTPResult.

That would indeed make sense to have a nHTTPResponseCode member in CPLHTTPResult. Contribution welcome.

Even more welcome, if you could at the same time clean up a few drivers that happen to parse the current error message to extract the error code from it, to update them to use the new member:

$ grep -r "HTTP error code" ../frmts/
../frmts/daas/daasdataset.cpp:                       "HTTP error code : ", strlen("HTTP error code : ")))
../frmts/daas/daasdataset.cpp:                    atoi(psResult->pszErrBuf + strlen("HTTP error code : "));
../frmts/eeda/eedacommon.cpp:                       "HTTP error code : ", strlen("HTTP error code : ")))
../frmts/eeda/eedacommon.cpp:                    atoi(psResult->pszErrBuf + strlen("HTTP error code : "));
../frmts/wms/gdalhttp.cpp:                strcmp(psResult->pszErrBuf, "HTTP error code : 404") == 0)

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

No branches or pull requests

3 participants