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

Obtain header when exception is thrown #102

Open
KingDuckZ opened this issue Aug 16, 2020 · 1 comment
Open

Obtain header when exception is thrown #102

KingDuckZ opened this issue Aug 16, 2020 · 1 comment
Assignees

Comments

@KingDuckZ
Copy link

The server I'm connecting to only accept a limited number of requests per day. The response header contains this information, like this:

HTTP/1.1 200 OK
Date: Mon, 22 Jun 2020 13:24:01 GMT
Content-Type: application/json
Content-Length: 1198
Connection: keep-alive
Set-Cookie: __cfduid=dda2f04d687c87c0f2eda6a4105be95e71592832241; expires=Wed, 22-Jul-20 13:24:01 GMT; path=/; domain=.originsro.org; HttpOnly; SameSite=Lax
X-RateLimit-Limit: 12
X-RateLimit-Remaining: 11
X-RateLimit-Reset: 1592835842
Retry-After: 3600
CF-Cache-Status: DYNAMIC
cf-request-id: 037dcc48ad0000066236a34200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5a7649877cc40662-LHR

X-Rate-Limit and Retry-After is what I'm after, and possibly X-RateLimit-Remaning as well. That is all good as I can grab that information from restc-cpp in normal situations, but when too many rquests are sent the server replies like this:

HTTP/1.1 429 TOO MANY REQUESTS
Date: Sun, 16 Aug 2020 15:06:51 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=dcff530e7dd3ce21af4b75531708104ea1597590411; expires=Tue, 15-Sep-20 15:06:51 GMT; path=/; domain=.originsro.org; HttpOnly; SameSite=Lax
X-RateLimit-Limit: 6
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1597672569
Retry-After: 82157
CF-Cache-Status: DYNAMIC
cf-request-id: 0499682fa20000dc4b342a4200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5c3c0fc5d8d3dc4b-LHR

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>429 Too Many Requests</title>
<h1>Too Many Requests</h1>
<p>6 per 1 day</p>

Which results in a c++ exception. I still need the data from the header to pause my program's timer for the correct amount of time, however restc-cpp throws with this backtrace:

#0  0x00007ffff7814a70 in __cxa_throw () from /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/libstdc++.so.6
#1  0x00007ffff7eeaf06 in restc_cpp::RequestImpl::ValidateReply (this=0x7ffff0010f00, reply=...) at ../../../code/cpp/orotool/subprojects/restc-cpp/restc-cpp/src/RequestImpl.cpp:204
#2  0x00007ffff7eed2a6 in restc_cpp::RequestImpl::GetReply (this=0x7ffff0010f00, ctx=...) at ../../../code/cpp/orotool/subprojects/restc-cpp/restc-cpp/src/RequestImpl.cpp:484
#3  0x00007ffff7eed434 in restc_cpp::RequestImpl::DoExecute (this=0x7ffff0010f00, ctx=...) at ../../../code/cpp/orotool/subprojects/restc-cpp/restc-cpp/src/RequestImpl.cpp:498
#4  0x00007ffff7eeaa54 in restc_cpp::RequestImpl::Execute (this=0x7ffff0010f00, ctx=...) at ../../../code/cpp/orotool/subprojects/restc-cpp/restc-cpp/src/RequestImpl.cpp:146
#5  0x000055555560e70a in restc_cpp::RequestBuilder::Execute (this=0x7ffff0010690) at ../../../code/cpp/orotool/subprojects/restc-cpp/restc-cpp/include/restc-cpp/RequestBuilder.h:381
#6  0x0000555555603dae in oro::(anonymous namespace)::<lambda(restc_cpp::Context&)>::operator()(restc_cpp::Context &) const (this=0x7fffdc000e20, ctx=...)
    at ../../../code/cpp/orotool/src/oro/api.cpp:151

and, in case it's useful, you can see here api.cpp:151.

Is there any way I can retrieve the header info I'm looking for when the server replies with an error?

@jgaa
Copy link
Owner

jgaa commented Aug 17, 2020

This is actually something I have run into myself also recently. I'll look into it.

@jgaa jgaa self-assigned this Aug 17, 2020
jgaa added a commit that referenced this issue Oct 30, 2020
Merging recent changes to master. 
All tests are passing under Debian and Ubuntu.

Issue #101 is reproducible under Windows. 

Working on issue #101, #102, #104, #105
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

2 participants