Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
095d05d9
Commit
095d05d9
authored
Jan 25, 2013
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generalize the transmit code, so it can be used for both req.* and
resp.* Submitted by: jonathan.huot@thomsonreuters.com
parent
1ba11856
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
68 deletions
+66
-68
a00011.vtc
bin/varnishtest/tests/a00011.vtc
+7
-1
vtc_http.c
bin/varnishtest/vtc_http.c
+59
-67
No files found.
bin/varnishtest/tests/a00011.vtc
View file @
095d05d9
...
@@ -2,12 +2,18 @@ varnishtest "test vtc gzip support"
...
@@ -2,12 +2,18 @@ varnishtest "test vtc gzip support"
server s1 {
server s1 {
rxreq
rxreq
expect req.http.content-length == "26"
expect req.bodylen == "26"
gunzip
expect req.bodylen == "3"
expect req.http.content-encoding == "gzip"
txresp -gzipbody FOO
txresp -gzipbody FOO
} -start
} -start
client c1 -connect ${s1_sock} {
client c1 -connect ${s1_sock} {
txreq
txreq
-gzipbody FOO
rxresp
rxresp
expect resp.http.content-length == "26"
expect resp.bodylen == "26"
expect resp.bodylen == "26"
gunzip
gunzip
expect resp.bodylen == "3"
expect resp.bodylen == "3"
...
...
bin/varnishtest/vtc_http.c
View file @
095d05d9
...
@@ -562,13 +562,14 @@ cmd_http_gunzip_body(CMD_ARGS)
...
@@ -562,13 +562,14 @@ cmd_http_gunzip_body(CMD_ARGS)
char
*
p
;
char
*
p
;
unsigned
l
;
unsigned
l
;
(
void
)
av
;
(
void
)
cmd
;
(
void
)
cmd
;
(
void
)
vl
;
(
void
)
vl
;
CAST_OBJ_NOTNULL
(
hp
,
priv
,
HTTP_MAGIC
);
CAST_OBJ_NOTNULL
(
hp
,
priv
,
HTTP_MAGIC
);
ONLY_CLIENT
(
hp
,
av
);
memset
(
&
vz
,
0
,
sizeof
vz
);
memset
(
&
vz
,
0
,
sizeof
vz
);
AN
(
hp
->
body
);
if
(
hp
->
body
[
0
]
!=
(
char
)
0x1f
||
hp
->
body
[
1
]
!=
(
char
)
0x8b
)
if
(
hp
->
body
[
0
]
!=
(
char
)
0x1f
||
hp
->
body
[
1
]
!=
(
char
)
0x8b
)
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Gunzip error: Body lacks gzip magics"
);
"Gunzip error: Body lacks gzip magics"
);
...
@@ -650,52 +651,21 @@ gzip_body(const struct http *hp, const char *txt, char **body, int *bodylen)
...
@@ -650,52 +651,21 @@ gzip_body(const struct http *hp, const char *txt, char **body, int *bodylen)
}
}
/**********************************************************************
/**********************************************************************
*
Transmit a
response
*
Handle common arguments of a transmited request or
response
*/
*/
static
void
static
char
*
const
*
cmd_http_txresp
(
CMD_ARGS
)
http_tx_parse_args
(
char
*
const
*
av
,
struct
vtclog
*
vl
,
struct
http
*
hp
,
char
*
body
)
{
{
struct
http
*
hp
;
const
char
*
proto
=
"HTTP/1.1"
;
const
char
*
status
=
"200"
;
const
char
*
msg
=
"Ok"
;
int
bodylen
=
0
;
int
bodylen
=
0
;
char
*
b
,
*
c
;
char
*
b
,
*
c
;
char
*
body
=
NULL
,
*
nullbody
;
char
*
nullbody
=
NULL
;
int
nolen
=
0
;
int
nolen
=
0
;
(
void
)
cmd
;
(
void
)
vl
;
(
void
)
vl
;
CAST_OBJ_NOTNULL
(
hp
,
priv
,
HTTP_MAGIC
);
ONLY_SERVER
(
hp
,
av
);
assert
(
!
strcmp
(
av
[
0
],
"txresp"
));
av
++
;
VSB_clear
(
hp
->
vsb
);
/* send a "Content-Length: 0" header unless something else happens */
REPLACE
(
body
,
""
);
nullbody
=
body
;
nullbody
=
body
;
for
(;
*
av
!=
NULL
;
av
++
)
{
if
(
!
strcmp
(
*
av
,
"-proto"
))
{
proto
=
av
[
1
];
av
++
;
}
else
if
(
!
strcmp
(
*
av
,
"-status"
))
{
status
=
av
[
1
];
av
++
;
}
else
if
(
!
strcmp
(
*
av
,
"-msg"
))
{
msg
=
av
[
1
];
av
++
;
continue
;
}
else
break
;
}
VSB_printf
(
hp
->
vsb
,
"%s %s %s%s"
,
proto
,
status
,
msg
,
nl
);
for
(;
*
av
!=
NULL
;
av
++
)
{
for
(;
*
av
!=
NULL
;
av
++
)
{
if
(
!
strcmp
(
*
av
,
"-nolen"
))
{
if
(
!
strcmp
(
*
av
,
"-nolen"
))
{
nolen
=
1
;
nolen
=
1
;
...
@@ -750,13 +720,60 @@ cmd_http_txresp(CMD_ARGS)
...
@@ -750,13 +720,60 @@ cmd_http_txresp(CMD_ARGS)
}
else
}
else
break
;
break
;
}
}
if
(
*
av
!=
NULL
)
vtc_log
(
hp
->
vl
,
0
,
"Unknown http txresp spec: %s
\n
"
,
*
av
);
if
(
body
!=
NULL
&&
!
nolen
)
if
(
body
!=
NULL
&&
!
nolen
)
VSB_printf
(
hp
->
vsb
,
"Content-Length: %d%s"
,
bodylen
,
nl
);
VSB_printf
(
hp
->
vsb
,
"Content-Length: %d%s"
,
bodylen
,
nl
);
VSB_cat
(
hp
->
vsb
,
nl
);
VSB_cat
(
hp
->
vsb
,
nl
);
if
(
body
!=
NULL
)
if
(
body
!=
NULL
)
VSB_bcat
(
hp
->
vsb
,
body
,
bodylen
);
VSB_bcat
(
hp
->
vsb
,
body
,
bodylen
);
return
av
;
}
/**********************************************************************
* Transmit a response
*/
static
void
cmd_http_txresp
(
CMD_ARGS
)
{
struct
http
*
hp
;
const
char
*
proto
=
"HTTP/1.1"
;
const
char
*
status
=
"200"
;
const
char
*
msg
=
"Ok"
;
char
*
body
=
NULL
;
(
void
)
cmd
;
(
void
)
vl
;
CAST_OBJ_NOTNULL
(
hp
,
priv
,
HTTP_MAGIC
);
ONLY_SERVER
(
hp
,
av
);
assert
(
!
strcmp
(
av
[
0
],
"txresp"
));
av
++
;
VSB_clear
(
hp
->
vsb
);
for
(;
*
av
!=
NULL
;
av
++
)
{
if
(
!
strcmp
(
*
av
,
"-proto"
))
{
proto
=
av
[
1
];
av
++
;
}
else
if
(
!
strcmp
(
*
av
,
"-status"
))
{
status
=
av
[
1
];
av
++
;
}
else
if
(
!
strcmp
(
*
av
,
"-msg"
))
{
msg
=
av
[
1
];
av
++
;
continue
;
}
else
break
;
}
VSB_printf
(
hp
->
vsb
,
"%s %s %s%s"
,
proto
,
status
,
msg
,
nl
);
/* send a "Content-Length: 0" header unless something else happens */
REPLACE
(
body
,
""
);
av
=
http_tx_parse_args
(
av
,
vl
,
hp
,
body
);
if
(
*
av
!=
NULL
)
vtc_log
(
hp
->
vl
,
0
,
"Unknown http txresp spec: %s
\n
"
,
*
av
);
http_write
(
hp
,
4
,
"txresp"
);
http_write
(
hp
,
4
,
"txresp"
);
}
}
...
@@ -780,6 +797,7 @@ cmd_http_rxreq(CMD_ARGS)
...
@@ -780,6 +797,7 @@ cmd_http_rxreq(CMD_ARGS)
vtc_log
(
hp
->
vl
,
0
,
"Unknown http rxreq spec: %s
\n
"
,
*
av
);
vtc_log
(
hp
->
vl
,
0
,
"Unknown http rxreq spec: %s
\n
"
,
*
av
);
http_rxhdr
(
hp
);
http_rxhdr
(
hp
);
http_splitheader
(
hp
,
1
);
http_splitheader
(
hp
,
1
);
hp
->
body
=
hp
->
rxbuf
+
hp
->
prxbuf
;
http_swallow_body
(
hp
,
hp
->
req
,
0
);
http_swallow_body
(
hp
,
hp
->
req
,
0
);
vtc_log
(
hp
->
vl
,
4
,
"bodylen = %s"
,
hp
->
bodylen
);
vtc_log
(
hp
->
vl
,
4
,
"bodylen = %s"
,
hp
->
bodylen
);
}
}
...
@@ -851,7 +869,6 @@ cmd_http_txreq(CMD_ARGS)
...
@@ -851,7 +869,6 @@ cmd_http_txreq(CMD_ARGS)
const
char
*
req
=
"GET"
;
const
char
*
req
=
"GET"
;
const
char
*
url
=
"/"
;
const
char
*
url
=
"/"
;
const
char
*
proto
=
"HTTP/1.1"
;
const
char
*
proto
=
"HTTP/1.1"
;
const
char
*
body
=
NULL
;
(
void
)
cmd
;
(
void
)
cmd
;
(
void
)
vl
;
(
void
)
vl
;
...
@@ -876,35 +893,10 @@ cmd_http_txreq(CMD_ARGS)
...
@@ -876,35 +893,10 @@ cmd_http_txreq(CMD_ARGS)
break
;
break
;
}
}
VSB_printf
(
hp
->
vsb
,
"%s %s %s%s"
,
req
,
url
,
proto
,
nl
);
VSB_printf
(
hp
->
vsb
,
"%s %s %s%s"
,
req
,
url
,
proto
,
nl
);
for
(;
*
av
!=
NULL
;
av
++
)
{
if
(
!
strcmp
(
*
av
,
"-hdr"
))
{
av
=
http_tx_parse_args
(
av
,
vl
,
hp
,
NULL
);
VSB_printf
(
hp
->
vsb
,
"%s%s"
,
av
[
1
],
nl
);
av
++
;
}
else
break
;
}
for
(;
*
av
!=
NULL
;
av
++
)
{
if
(
!
strcmp
(
*
av
,
"-body"
))
{
AZ
(
body
);
body
=
av
[
1
];
av
++
;
}
else
if
(
!
strcmp
(
*
av
,
"-bodylen"
))
{
AZ
(
body
);
body
=
synth_body
(
av
[
1
],
0
);
av
++
;
}
else
break
;
}
if
(
*
av
!=
NULL
)
if
(
*
av
!=
NULL
)
vtc_log
(
hp
->
vl
,
0
,
"Unknown http txreq spec: %s
\n
"
,
*
av
);
vtc_log
(
hp
->
vl
,
0
,
"Unknown http txreq spec: %s
\n
"
,
*
av
);
if
(
body
!=
NULL
)
VSB_printf
(
hp
->
vsb
,
"Content-Length: %ju%s"
,
(
uintmax_t
)
strlen
(
body
),
nl
);
VSB_cat
(
hp
->
vsb
,
nl
);
if
(
body
!=
NULL
)
{
VSB_cat
(
hp
->
vsb
,
body
);
VSB_cat
(
hp
->
vsb
,
nl
);
}
http_write
(
hp
,
4
,
"txreq"
);
http_write
(
hp
,
4
,
"txreq"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment