Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libwebsockets
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Fork
libwebsockets
Commits
fb5f33bb
Commit
fb5f33bb
authored
9 years ago
by
Andy Green
Browse files
Options
Downloads
Patches
Plain Diff
test server http proxy
Signed-off-by:
Andy Green
<
andy.green@linaro.org
>
parent
494418ab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog
+4
-0
4 additions, 0 deletions
changelog
test-server/test-server-http.c
+80
-1
80 additions, 1 deletion
test-server/test-server-http.c
test-server/test-server.h
+1
-0
1 addition, 0 deletions
test-server/test-server.h
with
85 additions
and
1 deletion
changelog
+
4
−
0
View file @
fb5f33bb
...
...
@@ -80,6 +80,10 @@ protocol string to its argument in URL format. If so, it stays in http[s]
client mode and doesn't upgrade to ws[s], allowing you to do generic http client
operations.
9) The test server has a new URI path http://localhost:7681/proxytest
If you visit here, a client connection to http://example.com:80 is spawned,
and the results piped on to your original connection.
User API additions
------------------
...
...
This diff is collapsed.
Click to expand it.
test-server/test-server-http.c
+
80
−
1
View file @
fb5f33bb
...
...
@@ -117,7 +117,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
void
*
in
,
size_t
len
)
{
struct
per_session_data__http
*
pss
=
(
struct
per_session_data__http
*
)
user
;
(
struct
per_session_data__http
*
)
user
,
*
pss1
;
unsigned
char
buffer
[
4096
+
LWS_PRE
];
unsigned
long
amount
,
file_len
,
sent
;
char
leaf_path
[
1024
];
...
...
@@ -167,6 +167,32 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
goto
try_to_reuse
;
}
#ifndef LWS_NO_CLIENT
if
(
!
strcmp
(
in
,
"/proxytest"
))
{
struct
lws_client_connect_info
i
;
if
(
lws_get_child
(
wsi
))
break
;
pss
->
client_finished
=
0
;
memset
(
&
i
,
0
,
sizeof
(
i
));
i
.
context
=
lws_get_context
(
wsi
);
i
.
address
=
"example.com"
;
i
.
port
=
80
;
i
.
ssl_connection
=
0
;
i
.
path
=
"/"
;
i
.
host
=
"example.com"
;
i
.
origin
=
NULL
;
i
.
method
=
"GET"
;
i
.
parent_wsi
=
wsi
;
if
(
!
lws_client_connect_via_info
(
&
i
))
{
lwsl_err
(
"proxy connect fail
\n
"
);
break
;
}
break
;
}
#endif
#ifdef LWS_WITH_CGI
if
(
!
strcmp
(
in
,
"/cgitest"
))
{
static
char
*
cmd
[]
=
{
...
...
@@ -366,6 +392,9 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
case
LWS_CALLBACK_HTTP_WRITEABLE
:
lwsl_info
(
"LWS_CALLBACK_HTTP_WRITEABLE
\n
"
);
if
(
pss
->
client_finished
)
return
-
1
;
if
(
pss
->
fd
==
LWS_INVALID_FILE
)
goto
try_to_reuse
;
#ifdef LWS_WITH_CGI
...
...
@@ -460,6 +489,56 @@ bail:
/* if we returned non-zero from here, we kill the connection */
break
;
#ifndef LWS_WITH_CLIENT
case
LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP
:
p
=
buffer
+
LWS_PRE
;
end
=
p
+
sizeof
(
buffer
)
-
LWS_PRE
;
if
(
lws_add_http_header_status
(
lws_get_parent
(
wsi
),
200
,
&
p
,
end
))
return
1
;
if
(
lws_add_http_header_by_token
(
lws_get_parent
(
wsi
),
WSI_TOKEN_HTTP_SERVER
,
(
unsigned
char
*
)
"libwebsockets"
,
13
,
&
p
,
end
))
return
1
;
if
(
lws_add_http_header_by_token
(
lws_get_parent
(
wsi
),
WSI_TOKEN_HTTP_CONTENT_TYPE
,
(
unsigned
char
*
)
"text/html"
,
9
,
&
p
,
end
))
return
1
;
#if 0
if (lws_add_http_header_content_length(lws_get_parent(wsi),
file_len, &p,
end))
return 1;
#endif
if
(
lws_finalize_http_header
(
lws_get_parent
(
wsi
),
&
p
,
end
))
return
1
;
*
p
=
'\0'
;
lwsl_info
(
"%s
\n
"
,
buffer
+
LWS_PRE
);
n
=
lws_write
(
lws_get_parent
(
wsi
),
buffer
+
LWS_PRE
,
p
-
(
buffer
+
LWS_PRE
),
LWS_WRITE_HTTP_HEADERS
);
if
(
n
<
0
)
return
-
1
;
break
;
case
LWS_CALLBACK_CLOSED_CLIENT_HTTP
:
return
-
1
;
break
;
case
LWS_CALLBACK_RECEIVE_CLIENT_HTTP
:
m
=
lws_write
(
lws_get_parent
(
wsi
),
in
,
len
,
LWS_WRITE_HTTP
);
if
(
m
<
0
)
return
1
;
break
;
case
LWS_CALLBACK_COMPLETED_CLIENT_HTTP
:
pss1
=
lws_wsi_user
(
lws_get_parent
(
wsi
));
pss1
->
client_finished
=
1
;
lws_callback_on_writable
(
lws_get_parent
(
wsi
));
return
-
1
;
break
;
#endif
#ifdef LWS_WITH_CGI
/* CGI IO events (POLLIN/OUT) appear here our demo user code policy is
*
...
...
This diff is collapsed.
Click to expand it.
test-server/test-server.h
+
1
−
0
View file @
fb5f33bb
...
...
@@ -71,6 +71,7 @@ struct per_session_data__http {
struct
lws_cgi_args
args
;
int
reason_bf
;
#endif
unsigned
int
client_finished
:
1
;
};
/*
...
...
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