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

[FEATURE] rest client event route #3489

Open
volga629-1 opened this issue Oct 7, 2024 · 1 comment
Open

[FEATURE] rest client event route #3489

volga629-1 opened this issue Oct 7, 2024 · 1 comment

Comments

@volga629-1
Copy link

volga629-1 commented Oct 7, 2024

Hello Everyone,
Rest client in 3.4 getting 400 response in ASYNC mode, but from curl shell returning 200 with proper JSON response. In debug log level 4 I don't see enough details to tell why invalid response.

 opensips -V
version: opensips 3.4.3 (x86_64/linux)
flags: STATS: On, DISABLE_NAGLE, USE_MCAST, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, HP_MALLOC, DBG_MALLOC, FAST_LOCK-ADAPTIVE_WAIT
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535
poll method support: poll, epoll, sigio_rt, select.
unknown revision: unknown
main.c compiled on 00:00:00 Jan 26 2024 with gcc 13

route[DST_LOOKUP] {
        $json(lookup) := "{}";
        $var(key) = "key";
        $var(dst_number) = $rU;
        $var(data) = "access_key=" + $var(key) + "&number=" + $var(dst_number) + "&format=0";
        async(rest_get("http://apilayer.net/api/validate?$var(data)", $json(lookup), $var(retrive), $var(rcode)), DST_LOOKUP_RESUME);
}

route[DST_LOOKUP_RESUME] {
        $var(rc) = $rc;
        # Minus or 1 report error
        if ($var(rc)<0 || $var(rc)==1) {
                xlog("[DST_LOOKUP_RESUME] [$rm] [$cfg_line] async rest_get() failed with $var(rc)\n");
                sl_send_reply(500, "Server Internal Error");
                exit;
        }

        xlog("[DST_LOOKUP_RESUME] [$rm] [$cfg_line] async rest_get() failed with $var(rc)\n");

        if($var(rcode)==200 || $var(rcode)==0) {
                for ($var(k) in $(json(lookup.keys)[*])) {
                        xlog("[DST_LOOKUP_RESUME] [$rm] [$cfg_line] dst number $$var(dst_number)|$var(dst_number)
                        retrived key $$var(k)|$var(k)\n");
                }
                exit;
                #$var(data) = $var(dst_number) + "_" + $json(lookup/country_name) + "_" + $json(lookup/country_name);
                #cache_store("local", "$var(store_key)", "$var(data)");
        }

        if($var(rcode)!=200 || $var(rcode)!=0) {
                xlog("[DST_LOOKUP_RESUME] [$rm] [$cfg_line] Async rest_get() headers=$var(retrive) rcode=$var(rcode)\n");
                sl_send_reply(403, "Forbidden");
                exit;
        }
        # Temporary test purpouse.
        exit;        
}

Also rest client is NOT returning actual 400, only tcpdump I can see 400.

	<html><body><h1>400 Bad request</h1>
	Your browser sent an invalid request.
	</body></html>
E.....@.#.Q."....Eq..P.<..KO./:....F.......
......._HTTP/1.1 400 Bad request

How is possible to find out what is incorrect ?
Might be as an Idea to introduce

event_route[E_CURL_RESPONSE] {
         xlog("[E_CURL_RESPONSE] [$cfg_line] API call response $param(code), $param(reason)\n");
}

@volga629-1
Copy link
Author

volga629-1 commented Oct 8, 2024

Log


Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: ERROR:rest_client:_resume_async_http_req: async GET timed out, URL: 
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:rest_client:del_transfer: del fd 135
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:rest_client:_resume_async_http_req: download finished, but an HTTP status is not available (timed_out: 1)
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:rest_client:_resume_async_http_req: HTTP response code: 0
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:tm:io_watch_del: [TCP_worker] io_watch_del op on index -1 135 (0x55c257c23b80, 135, -1, 0x10,0x1) fd_no=12 called
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:comp_scriptvar: int 26: 1 / 0
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:comp_scriptvar: int 20: 1 / 1
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: NOTICE:[DST_LOOKUP_RESUME] [MESSAGE] [862] async rest_get() failed with 1
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:MD5StringArray: MD5 calculated: f9ce38d136d61fd87825e3006abb3282
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:parse_headers: flags=ffffffffffffffff
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:tcp_conn_get: con found in state 0
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:tcp_conn_get: tcp connection found (0x7f24edc42fc0) already in this process ( 11 ) , fd = 129
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:proto_tcp_send: sending via fd 129...
Oct  8 11:17:20 dev1-msg opensips[461765]: [OSIP-250-SMPP] [461765]: DBG:core:tsend_stream_async: Async successful write from first try on 0x7f24edc42fc0

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