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
7820ecde
Commit
7820ecde
authored
Aug 07, 2014
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce the HTTP_Encode() and HTTP_Decode() functions which pack
a http response into bytestring.
parent
c62d0b6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
0 deletions
+90
-0
cache.h
bin/varnishd/cache/cache.h
+2
-0
cache_http.c
bin/varnishd/cache/cache_http.c
+88
-0
No files found.
bin/varnishd/cache/cache.h
View file @
7820ecde
...
...
@@ -949,6 +949,8 @@ void http_PutResponse(struct http *to, const char *proto, uint16_t status,
const
char
*
response
);
void
http_FilterReq
(
struct
http
*
to
,
const
struct
http
*
fm
,
unsigned
how
);
void
http_FilterResp
(
const
struct
http
*
fm
,
struct
http
*
to
,
unsigned
how
);
uint8_t
*
HTTP_Encode
(
const
struct
http
*
fm
,
struct
ws
*
ws
,
unsigned
how
);
int
HTTP_Decode
(
struct
http
*
to
,
uint8_t
*
fm
);
void
http_ForceHeader
(
struct
http
*
to
,
const
char
*
hdr
,
const
char
*
val
);
void
http_PrintfHeader
(
struct
http
*
to
,
const
char
*
fmt
,
...)
__printflike
(
2
,
3
);
...
...
bin/varnishd/cache/cache_http.c
View file @
7820ecde
...
...
@@ -36,6 +36,7 @@
#include "cache.h"
#include "vend.h"
#include "vct.h"
#define HTTPH(a, b, c) char b[] = "*" a ":";
...
...
@@ -624,6 +625,93 @@ http_EstimateWS(const struct http *fm, unsigned how, uint16_t *nhd)
return
(
l
);
}
/*--------------------------------------------------------------------
* Encode http struct as byte string.
*/
uint8_t
*
HTTP_Encode
(
const
struct
http
*
fm
,
struct
ws
*
ws
,
unsigned
how
)
{
unsigned
u
,
w
;
uint16_t
n
;
uint8_t
*
p
,
*
e
;
u
=
WS_Reserve
(
ws
,
0
);
p
=
(
uint8_t
*
)
ws
->
f
;
e
=
(
uint8_t
*
)
ws
->
f
+
u
;
if
(
p
+
5
>
e
)
{
WS_Release
(
ws
,
0
);
return
(
NULL
);
}
assert
(
fm
->
nhd
<
fm
->
shd
);
n
=
HTTP_HDR_FIRST
-
3
;
vbe16enc
(
p
+
2
,
fm
->
status
);
p
+=
4
;
CHECK_OBJ_NOTNULL
(
fm
,
HTTP_MAGIC
);
for
(
u
=
0
;
u
<
fm
->
nhd
;
u
++
)
{
if
(
u
==
HTTP_HDR_METHOD
||
u
==
HTTP_HDR_URL
)
continue
;
AN
(
fm
->
hd
[
u
].
b
);
AN
(
fm
->
hd
[
u
].
e
);
if
(
fm
->
hdf
[
u
]
&
HDF_FILTER
)
continue
;
#define HTTPH(a, b, c) \
if (((c) & how) && http_IsHdr(&fm->hd[u], (b))) \
continue;
#include "tbl/http_headers.h"
#undef HTTPH
w
=
Tlen
(
fm
->
hd
[
u
])
+
1L
;
if
(
p
+
w
+
1
>
e
)
{
WS_Release
(
ws
,
0
);
return
(
NULL
);
}
memcpy
(
p
,
fm
->
hd
[
u
].
b
,
w
);
p
+=
w
;
n
++
;
}
*
p
++
=
'\0'
;
assert
(
p
<=
e
);
e
=
(
uint8_t
*
)
ws
->
f
;
vbe16enc
(
e
,
n
+
1
);
WS_ReleaseP
(
ws
,
(
void
*
)
p
);
return
(
e
);
}
/*--------------------------------------------------------------------
* Decode byte string into http struct
*
* XXX: cannot make fm const because to->hd isn't.
*/
int
HTTP_Decode
(
struct
http
*
to
,
uint8_t
*
fm
)
{
CHECK_OBJ_NOTNULL
(
to
,
HTTP_MAGIC
);
AN
(
fm
);
if
(
vbe16dec
(
fm
)
>
to
->
shd
)
return
(
-
1
);
to
->
status
=
vbe16dec
(
fm
+
2
);
fm
+=
4
;
for
(
to
->
nhd
=
0
;
to
->
nhd
<
to
->
shd
;
to
->
nhd
++
)
{
if
(
to
->
nhd
==
HTTP_HDR_METHOD
||
to
->
nhd
==
HTTP_HDR_URL
)
{
to
->
hd
[
to
->
nhd
].
b
=
NULL
;
to
->
hd
[
to
->
nhd
].
e
=
NULL
;
continue
;
}
if
(
*
fm
==
'\0'
)
return
(
0
);
to
->
hd
[
to
->
nhd
].
b
=
(
void
*
)
fm
;
fm
=
strchr
((
void
*
)
fm
,
'\0'
);
to
->
hd
[
to
->
nhd
].
e
=
(
void
*
)
fm
;
fm
++
;
if
(
to
->
vsl
!=
NULL
)
http_VSLH
(
to
,
to
->
nhd
);
}
return
(
-
1
);
}
/*--------------------------------------------------------------------*/
static
void
...
...
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