1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
|
.\" Man page generated from reStructuredText.
.
.TH VMOD_STD 3 "" "" ""
.SH NAME
vmod_std \- Varnish Standard Module
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.\"
.
.\" NB: This file is machine generated, DO NOT EDIT!
.
.\"
.
.\" Edit vmod.vcc and run make instead
.
.\"
.
.SH SYNOPSIS
.sp
import std [from "path"] ;
.SH DESCRIPTION
.sp
\fIvmod_std\fP contains basic functions which are part and parcel of Varnish,
but which for reasons of architecture fit better in a VMOD.
.sp
One particular class of functions in vmod_std is the conversions functions
which all have the form:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
TYPE type(STRING, TYPE)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
These functions attempt to convert STRING to the TYPE, and if that fails,
they return the second argument, which must have the given TYPE.
.SH CONTENTS
.INDENT 0.0
.IP \(bu 2
STRING toupper(STRING)
.IP \(bu 2
STRING tolower(STRING)
.IP \(bu 2
VOID set_ip_tos(INT)
.IP \(bu 2
REAL random(REAL, REAL)
.IP \(bu 2
VOID log(STRING)
.IP \(bu 2
VOID syslog(INT, STRING)
.IP \(bu 2
STRING fileread(PRIV_CALL, STRING)
.IP \(bu 2
VOID collect(HEADER)
.IP \(bu 2
DURATION duration(STRING, DURATION)
.IP \(bu 2
INT integer(STRING, INT)
.IP \(bu 2
IP ip(STRING, IP)
.IP \(bu 2
REAL real(STRING, REAL)
.IP \(bu 2
INT real2integer(REAL, INT)
.IP \(bu 2
TIME real2time(REAL, TIME)
.IP \(bu 2
INT time2integer(TIME, INT)
.IP \(bu 2
REAL time2real(TIME, REAL)
.IP \(bu 2
BOOL healthy(BACKEND)
.IP \(bu 2
INT port(IP)
.IP \(bu 2
VOID rollback(HTTP)
.IP \(bu 2
VOID timestamp(STRING)
.IP \(bu 2
STRING querysort(STRING)
.IP \(bu 2
BOOL cache_req_body(BYTES)
.IP \(bu 2
STRING strstr(STRING, STRING)
.IP \(bu 2
TIME time(STRING, TIME)
.UNINDENT
.SS toupper
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
STRING toupper(STRING s)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to uppercase.
.TP
.B Example
set beresp.http.scream = std.toupper("yes!");
.UNINDENT
.SS tolower
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
STRING tolower(STRING s)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to lowercase.
.TP
.B Example
set beresp.http.nice = std.tolower("VerY");
.UNINDENT
.SS set_ip_tos
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
VOID set_ip_tos(INT tos)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Sets the IP type\-of\-service (TOS) field for the current session
to \fItos\fP\&.
Please note that the TOS field is not removed by the end of the
request so probably want to set it on every request should you
utilize it.
.TP
.B Example
.nf
if (req.url ~ "^/slow/") {
.in +2
std.set_ip_tos(0);
.in -2
}
.fi
.sp
.UNINDENT
.SS random
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
REAL random(REAL lo, REAL hi)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Returns a random real number between \fIlo\fP and \fIhi\fP\&.
This function uses the "testable" random generator in varnishd
which enables determinstic tests to be run (See m00002.vtc).
This function should not be used for cryptographic applications.
.TP
.B Example
set beresp.http.random\-number = std.random(1, 100);
.UNINDENT
.SS log
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
VOID log(STRING s)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Logs the string \fIs\fP to the shared memory log, using VSL tag
\fISLT_VCL_Log\fP\&.
.TP
.B Example
std.log("Something fishy is going on with the vhost " + req.http.host);
.UNINDENT
.SS syslog
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
VOID syslog(INT priority, STRING s)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Logs the string \fIs\fP to syslog tagged with \fIpriority\fP\&. \fIpriority\fP
is formed by ORing the facility and level values. See your
system\(aqs syslog.h file for possible values.
.TP
.B Example
std.syslog(9, "Something is wrong");
.sp
This will send a message to syslog using LOG_USER | LOG_ALERT.
.UNINDENT
.SS fileread
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
STRING fileread(PRIV_CALL, STRING)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Reads a file and returns a string with the content. Please
note that it is not recommended to send variables to this
function the caching in the function doesn\(aqt take this into
account. Also, files are not re\-read.
.TP
.B Example
set beresp.http.served\-by = std.fileread("/etc/hostname");
.UNINDENT
.SS collect
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
VOID collect(HEADER hdr)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Collapses multiple \fIhdr\fP headers into one long header.
The header values are joined with a comma (",").
.sp
Care should be taken when collapsing headers. In particular
collapsing Set\-Cookie will lead to unexpected results on the
browser side.
.TP
.B Example
std.collect(req.http.cookie);
.UNINDENT
.SS duration
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
DURATION duration(STRING s, DURATION fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to seconds. \fIs\fP must be quantified
with ms (milliseconds), s (seconds), m (minutes), h (hours),
d (days), w (weeks) or y (years) units. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
set beresp.ttl = std.duration("1w", 3600s);
.UNINDENT
.SS integer
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
INT integer(STRING s, INT fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to an integer. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
.nf
if (std.integer(req.http.foo, 0) > 5) {
.in +2
\&...
.in -2
}
.fi
.sp
.UNINDENT
.SS ip
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
IP ip(STRING s, IP fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to the first IP number returned by
the system library function getaddrinfo(3). If conversion
fails, \fIfallback\fP will be returned.
.TP
.B Example
.nf
if (std.ip(req.http.X\-forwarded\-for, "0.0.0.0") ~ my_acl) {
.in +2
\&...
.in -2
}
.fi
.sp
.UNINDENT
.SS real
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
REAL real(STRING s, REAL fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to a real. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
.nf
if (std.real(req.http.foo, 0.0) > 5.5) {
.in +2
\&...
.in -2
}
.fi
.sp
.UNINDENT
.SS real2integer
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
INT real2integer(REAL r, INT fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the real \fIr\fP to an integer. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
set req.http.integer = std.real2integer(1140618699.00, 0);
.UNINDENT
.SS real2time
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
TIME real2time(REAL r, TIME fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the real \fIr\fP to a time. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
set req.http.time = std.real2time(1140618699.00, now);
.UNINDENT
.SS time2integer
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
INT time2integer(TIME t, INT fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the time \fIt\fP to a integer. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
set req.http.int = std.time2integer(now, 0);
.UNINDENT
.SS time2real
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
REAL time2real(TIME t, REAL fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the time \fIt\fP to a real. If conversion fails,
\fIfallback\fP will be returned.
.TP
.B Example
set req.http.real = std.time2real(now, 1.0);
.UNINDENT
.SS healthy
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
BOOL healthy(BACKEND be)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Returns \fItrue\fP if the backend \fIbe\fP is healthy.
.UNINDENT
.SS port
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
INT port(IP ip)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Returns the port number of the IP address \fIip\fP\&.
.UNINDENT
.SS rollback
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
VOID rollback(HTTP h)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Restores the \fIh\fP HTTP headers to their original state.
.TP
.B Example
std.rollback(bereq);
.UNINDENT
.SS timestamp
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
VOID timestamp(STRING s)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Introduces a timestamp in the log with the current time, using
the string \fIs\fP as the label. This is useful to time the execution
of lengthy VCL procedures, and makes the timestamps inserted
automatically by Varnish more accurate.
.TP
.B Example
std.timestamp("curl\-request");
.UNINDENT
.SS querysort
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
STRING querysort(STRING)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Sorts the query string for cache normalization purposes.
.TP
.B Example
set req.url = std.querysort(req.url);
.UNINDENT
.SS cache_req_body
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
BOOL cache_req_body(BYTES size)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Caches the request body if it is smaller than \fIsize\fP\&. Returns
\fItrue\fP if the body was cached, \fIfalse\fP otherwise.
.sp
Normally the request body is not available after sending it to
the backend. By caching it is possible to retry pass operations,
e.g. POST and PUT.
.TP
.B Example
.nf
if (std.cache_req_body(1KB)) {
.in +2
\&...
.in -2
}
.fi
.sp
.UNINDENT
.SS strstr
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
STRING strstr(STRING s1, STRING s2)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Returns a string beginning at the first occurrence of the string
\fIs2\fP in the string \fIs1\fP, or an empty string if \fIs2\fP is not found.
.sp
Note that the comparison is case sensitive.
.TP
.B Example
.nf
if (std.strstr(req.url, req.http.restrict)) {
.in +2
\&...
.in -2
}
.fi
.sp
.sp
This will check if the content of req.http.restrict occurs
anywhere in req.url.
.UNINDENT
.SS time
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
TIME time(STRING s, TIME fallback)
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B Description
Converts the string \fIs\fP to a time. If conversion fails,
\fIfallback\fP will be returned.
.sp
Supported formats:
.nf
"Sun, 06 Nov 1994 08:49:37 GMT"
"Sunday, 06\-Nov\-94 08:49:37 GMT"
"Sun Nov 6 08:49:37 1994"
"1994\-11\-06T08:49:37"
"784111777.00"
"784111777"
.fi
.sp
.TP
.B Example
.nf
if (std.time(resp.http.last\-modified, now) < now \- 1w) {
.in +2
\&...
.in -2
}
.fi
.sp
.UNINDENT
.SH SEE ALSO
.INDENT 0.0
.IP \(bu 2
\fIvarnishd(1)\fP
.IP \(bu 2
\fIvsl(7)\fP
.UNINDENT
.SH HISTORY
.sp
The Varnish standard module was released along with Varnish Cache 3.0.
This manual page was written by Per Buer with help from Martin Blix
Grydeland.
.SH COPYRIGHT
.sp
This document is licensed under the same licence as Varnish
itself. See LICENCE for details.
.INDENT 0.0
.IP \(bu 2
Copyright (c) 2010\-2015 Varnish Software AS
.UNINDENT
.SH COPYRIGHT
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
Copyright (c) 2010\-2015 Varnish Software AS
All rights reserved.
Author: Poul\-Henning Kamp <phk@FreeBSD.org>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS \(ga\(gaAS IS\(aq\(aq AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
.ft P
.fi
.UNINDENT
.UNINDENT
.\" Generated by docutils manpage writer.
.
|