Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
18
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
cellframe-sdk
Commits
d903515d
Commit
d903515d
authored
4 years ago
by
Dmitriy A. Gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[*] Fixed caching mechanism
parent
cbceec45
No related branches found
No related tags found
No related merge requests found
Pipeline
#7215
passed with stage
in 11 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dap-sdk/net/server/http_server/dap_http_simple.c
+6
-1
6 additions, 1 deletion
dap-sdk/net/server/http_server/dap_http_simple.c
dap-sdk/net/server/http_server/http_client/dap_http_client.c
+42
-27
42 additions, 27 deletions
dap-sdk/net/server/http_server/http_client/dap_http_client.c
with
48 additions
and
28 deletions
dap-sdk/net/server/http_server/dap_http_simple.c
+
6
−
1
View file @
d903515d
...
@@ -446,10 +446,15 @@ size_t dap_http_simple_reply(dap_http_simple_t *a_http_simple, void *a_data, siz
...
@@ -446,10 +446,15 @@ size_t dap_http_simple_reply(dap_http_simple_t *a_http_simple, void *a_data, siz
*/
*/
dap_http_cache_t
*
dap_http_simple_make_cache_from_reply
(
dap_http_simple_t
*
a_http_simple
,
time_t
a_ts_expire
)
dap_http_cache_t
*
dap_http_simple_make_cache_from_reply
(
dap_http_simple_t
*
a_http_simple
,
time_t
a_ts_expire
)
{
{
// Because we call it from callback, we have no headers ready for output
a_http_simple
->
http_client
->
out_content_length
=
a_http_simple
->
reply_size
;
a_http_simple
->
http_client
->
reply_status_code
=
200
;
dap_http_client_out_header_generate
(
a_http_simple
->
http_client
);
return
dap_http_cache_update
(
a_http_simple
->
http_client
->
http
->
url_proc
,
return
dap_http_cache_update
(
a_http_simple
->
http_client
->
http
->
url_proc
,
a_http_simple
->
reply_byte
,
a_http_simple
->
reply_byte
,
a_http_simple
->
reply_size
,
a_http_simple
->
reply_size
,
a_http_simple
->
http_client
->
out_headers
,
NULL
,
200
,
a_ts_expire
);
a_http_simple
->
http_client
->
out_headers
,
NULL
,
200
,
a_ts_expire
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
dap-sdk/net/server/http_server/http_client/dap_http_client.c
+
42
−
27
View file @
d903515d
...
@@ -88,12 +88,23 @@ void dap_http_client_new( dap_events_socket_t *a_esocket, void *a_arg )
...
@@ -88,12 +88,23 @@ void dap_http_client_new( dap_events_socket_t *a_esocket, void *a_arg )
l_http_client
->
state_write
=
DAP_HTTP_CLIENT_STATE_NONE
;
l_http_client
->
state_write
=
DAP_HTTP_CLIENT_STATE_NONE
;
pthread_rwlock_rdlock
(
&
l_http_client
->
http
->
url_proc
->
cache_rwlock
);
pthread_rwlock_rdlock
(
&
l_http_client
->
http
->
url_proc
->
cache_rwlock
);
if
(
l_http_client
->
http
->
url_proc
->
cache
){
dap_http_cache_t
*
l_http_cache
=
l_http_client
->
http
->
url_proc
->
cache
;
if
(
!
l_http_client
->
http
->
url_proc
->
cache
->
ts_expire
||
l_http_client
->
http
->
url_proc
->
cache
->
ts_expire
>=
time
(
NULL
)
){
if
(
l_http_cache
){
l_http_client
->
out_headers
=
dap_http_headers_dup
(
l_http_client
->
http
->
url_proc
->
cache
->
headers
);
if
(
!
l_http_cache
->
ts_expire
||
l_http_cache
->
ts_expire
>=
time
(
NULL
)
){
l_http_client
->
out_headers
=
dap_http_headers_dup
(
l_http_cache
->
headers
);
l_http_client
->
out_content_length
=
l_http_cache
->
body_size
;
l_http_client
->
reply_status_code
=
l_http_cache
->
response_code
;
if
(
l_http_cache
->
response_phrase
)
strncpy
(
l_http_client
->
reply_reason_phrase
,
l_http_cache
->
response_phrase
,
sizeof
(
l_http_client
->
reply_reason_phrase
)
-
1
);
if
(
s_debug_http
)
if
(
s_debug_http
)
log_it
(
L_DEBUG
,
"%d Out: prepare cached headers"
,
l_http_client
->
esocket
->
socket
);
log_it
(
L_DEBUG
,
"%d Out: prepare cached headers"
,
l_http_client
->
esocket
->
socket
);
}
else
if
(
l_http_cache
){
pthread_rwlock_unlock
(
&
l_http_client
->
http
->
url_proc
->
cache_rwlock
);
pthread_rwlock_wrlock
(
&
l_http_client
->
http
->
url_proc
->
cache_rwlock
);
dap_http_cache_delete
(
l_http_cache
);
l_http_client
->
http
->
url_proc
->
cache
=
NULL
;
}
}
}
}
pthread_rwlock_unlock
(
&
l_http_client
->
http
->
url_proc
->
cache_rwlock
);
pthread_rwlock_unlock
(
&
l_http_client
->
http
->
url_proc
->
cache_rwlock
);
...
@@ -594,7 +605,7 @@ void dap_http_client_write( dap_events_socket_t * a_esocket, void *a_arg )
...
@@ -594,7 +605,7 @@ void dap_http_client_write( dap_events_socket_t * a_esocket, void *a_arg )
if
(
l_sent
){
if
(
l_sent
){
if
(
l_http_client
->
out_cache_position
+
l_sent
>=
l_http_client
->
proc
->
cache
->
body_size
){
// All is sent
if
(
l_http_client
->
out_cache_position
+
l_sent
>=
l_http_client
->
proc
->
cache
->
body_size
){
// All is sent
if
(
s_debug_http
)
if
(
s_debug_http
)
log_it
(
L_DEBUG
,
"
%d
Out: All cached data over, signal to close connection"
,
l_http_client
->
esocket
->
socket
);
log_it
(
L_DEBUG
,
"Out
%d
: All cached data over, signal to close connection"
,
l_http_client
->
esocket
->
socket
);
l_http_client
->
esocket
->
flags
|=
DAP_SOCK_SIGNAL_CLOSE
;
l_http_client
->
esocket
->
flags
|=
DAP_SOCK_SIGNAL_CLOSE
;
l_http_client
->
state_write
=
DAP_HTTP_CLIENT_STATE_NONE
;
l_http_client
->
state_write
=
DAP_HTTP_CLIENT_STATE_NONE
;
dap_events_socket_set_writable_unsafe
(
a_esocket
,
false
);
dap_events_socket_set_writable_unsafe
(
a_esocket
,
false
);
...
@@ -615,33 +626,37 @@ void dap_http_client_write( dap_events_socket_t * a_esocket, void *a_arg )
...
@@ -615,33 +626,37 @@ void dap_http_client_write( dap_events_socket_t * a_esocket, void *a_arg )
* @brief dap_http_client_out_header_generate Produce general headers
* @brief dap_http_client_out_header_generate Produce general headers
* @param cl_ht HTTP client instance
* @param cl_ht HTTP client instance
*/
*/
void
dap_http_client_out_header_generate
(
dap_http_client_t
*
cl_h
t
)
void
dap_http_client_out_header_generate
(
dap_http_client_t
*
a_http_clien
t
)
{
{
char
buf
[
1024
];
char
buf
[
1024
];
if
(
cl_ht
->
reply_status_code
==
200
)
{
if
(
a_http_client
->
reply_status_code
==
200
)
{
if
(
s_debug_http
)
if
(
cl_ht
->
out_last_modified
)
{
log_it
(
L_DEBUG
,
"Out headers generate for sock %d"
,
a_http_client
->
esocket
->
socket
);
dap_time_to_str_rfc822
(
buf
,
sizeof
(
buf
),
cl_ht
->
out_last_modified
);
if
(
a_http_client
->
out_last_modified
)
{
dap_http_header_add
(
&
cl_ht
->
out_headers
,
"Last-Modified"
,
buf
);
dap_time_to_str_rfc822
(
buf
,
sizeof
(
buf
),
a_http_client
->
out_last_modified
);
}
dap_http_header_add
(
&
a_http_client
->
out_headers
,
"Last-Modified"
,
buf
);
if
(
cl_ht
->
out_content_type
[
0
]
)
{
}
dap_http_header_add
(
&
cl_ht
->
out_headers
,
"Content-Type"
,
cl_ht
->
out_content_type
);
if
(
a_http_client
->
out_content_type
[
0
]
)
{
log_it
(
L_DEBUG
,
"output: Content-Type = '%s'"
,
cl_ht
->
out_content_type
);
dap_http_header_add
(
&
a_http_client
->
out_headers
,
"Content-Type"
,
a_http_client
->
out_content_type
);
}
log_it
(
L_DEBUG
,
"output: Content-Type = '%s'"
,
a_http_client
->
out_content_type
);
if
(
cl_ht
->
out_content_length
)
{
}
dap_snprintf
(
buf
,
sizeof
(
buf
),
"%llu"
,(
unsigned
long
long
)
cl_ht
->
out_content_length
);
if
(
a_http_client
->
out_content_length
)
{
dap_http_header_add
(
&
cl_ht
->
out_headers
,
"Content-Length"
,
buf
);
dap_snprintf
(
buf
,
sizeof
(
buf
),
"%llu"
,(
unsigned
long
long
)
a_http_client
->
out_content_length
);
log_it
(
L_DEBUG
,
"output: Content-Length = %llu"
,
cl_ht
->
out_content_length
);
dap_http_header_add
(
&
a_http_client
->
out_headers
,
"Content-Length"
,
buf
);
}
log_it
(
L_DEBUG
,
"output: Content-Length = %llu"
,
a_http_client
->
out_content_length
);
}
}
}
else
if
(
s_debug_http
)
log_it
(
L_WARNING
,
"Out headers: nothing generate for sock %d, http code %d"
,
a_http_client
->
esocket
->
socket
,
a_http_client
->
reply_status_code
);
if
(
cl
_ht
->
out_connection_close
||
!
cl_h
t
->
keep_alive
)
if
(
a
_ht
tp_client
->
out_connection_close
||
!
a_http_clien
t
->
keep_alive
)
dap_http_header_add
(
&
cl_h
t
->
out_headers
,
"Connection"
,
"Close"
);
dap_http_header_add
(
&
a_http_clien
t
->
out_headers
,
"Connection"
,
"Close"
);
dap_http_header_add
(
&
cl
_ht
->
out_headers
,
"Server-Name"
,
cl_h
t
->
http
->
server_name
);
dap_http_header_add
(
&
a
_ht
tp_client
->
out_headers
,
"Server-Name"
,
a_http_clien
t
->
http
->
server_name
);
log_it
(
L_DEBUG
,
"Output: Headers generated"
);
log_it
(
L_DEBUG
,
"Output: Headers generated"
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment