varnishcache-friends / varnish3to4

Varnish 3 to 4 migration script
BSD 2-Clause "Simplified" License
125 stars 25 forks source link

No more bereq obj in sub vcl_miss or vcl_pass #2

Closed matheuzzy closed 7 years ago

matheuzzy commented 7 years ago

See more here:

http://book.varnish-software.com/3.0/VCL_functions.html#variable-availability-in-vcl VS

http://book.varnish-software.com/4.0/chapters/VCL_Basics.html#variables-in-vcl-subroutines

fgsch commented 7 years ago

This looks good. Thanks for the PR.

Mind updating the README as well before I apply it?

matheuzzy commented 7 years ago

Sure! I also found another possible replacement in vcl_pipe: req. TO bereq. I will update them and resend it.

Thank you for this tool!

fgsch commented 7 years ago

Thanks. Re vcl_pipe, actually both are available so not much we can do in that case.

matheuzzy commented 7 years ago

Uuh, I see. Than it must be an error in the book. I did a test and, obviously you are right, the VCL is compiling with both :)

fgsch commented 7 years ago

Applied.

Thanks again for the PR.

huayra commented 7 years ago

Hi,

Sorry to bump here, but I have to ask: The Varnish Book? If so, could you point me to were the error is so we can highlight that difference between 3 and 4?

Thanks! On Dec 3, 2016 8:20 PM, "Valentin Matei" notifications@github.com wrote:

Uuh, I see. Than it must be an error in the book. I did a test and, obviously you are right, the VCL is compiling with both :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fgsch/varnish3to4/pull/2#issuecomment-264659568, or mute the thread https://github.com/notifications/unsubscribe-auth/AAURXJ8LquGCxwK_6zLkSzLBeBcEBNwEks5rEcEOgaJpZM4LDYVR .

matheuzzy commented 7 years ago

Hello,

The story line is:

After doing the test below, I realized there might be 2 issues regarding objs in vcl_pipe and one suggestion. What do you think?

  1. In the Varnish Book "R" access to req obj for vcl_pipe subroutine should be added.
  2. VCC-compiler should raise an error for trying to write on req obj (like "Message from VCC-compiler: Variable 'req.http.W-Req' is read only. ")
  3. Since req & bereq are the same in vcl_pipe, maybe is good to be auto-replaced by this tool; req -> bereq.
varnishtest "Test R/W in pipe on req and bereq obj"

server s1 {
    rxreq
    txresp
    expect req.http.W-Req == <undef>
    expect req.http.R-Req == "R-from-req"
    expect req.http.W-Bereq == "W-on-bereq"
    expect req.http.R-Bereq == "W-on-bereq"
}

server s1 -start

varnish v1 -vcl+backend {
    sub vcl_recv {
        set req.http.To-Read = "R-from-req";
        return (pipe);
    }

    sub vcl_pipe {

        # write to req
        set req.http.W-Req = "W-on-req";
        # read from req
        set bereq.http.R-Req = req.http.To-Read;

        # write to bereq
        set bereq.http.W-Bereq = "W-on-bereq";
        # read from bereq
        set bereq.http.R-Bereq = bereq.http.W-Bereq;
    }

    sub vcl_deliver {
        set obj.http.W-Obj = "W-on-obj";
    }
} -start

client c1 {
    txreq
    rxresp
} -run
huayra commented 7 years ago

Hello Valentin,

Just wanted to mention that this has been fixed:

https://github.com/varnish/Varnish-Book/commit/e1c7d132ef1f98f4bdb5af7dec4b8a60d8690dd8

Thanks for letting us know!

Best, Rubén. On Dec 5, 2016 12:46 PM, "Valentin Matei" notifications@github.com wrote:

Hello,

The story line is:

  • I used this tool to migrate a VCL 3 to 4
  • After vcl.4 file was generated, I tried to compile it
  • Varnishd raised some errors about using bereq in sub vcl_miss and vcl_pass
  • I read about variable availability in the varnish manual and I made this PR
  • I also noticed some changes in the vcl_pipe about req. and bereq. and I suggested @fgsch https://github.com/fgsch to include this also, but he told me that both are available and that was true, the VCL was compiling with both.

After doing the test below, I realized there might be 2 issues regarding objs in vcl_pipe and one suggestion. What do you think?

  1. In the Varnish Book http://book.varnish-software.com/4.0/chapters/VCL_Basics.html#variables-in-vcl-subroutines "R" access to req obj for vcl_pipe subroutine should be added.
  2. VCC-compiler should raise an error for trying to write on req obj (like "Message from VCC-compiler: Variable 'req.http.W-Req' is read only. ")
  3. Since req & bereq are the same in vcl_pipe, maybe is good to be auto-replaced by this tool; req -> bereq.

`varnishtest "Test R/W in pipe on req and bereq obj"

server s1 { rxreq txresp expect req.http.W-Req == expect req.http.R-Req == "R-from-req" expect req.http.W-Bereq == "W-on-bereq" expect req.http.R-Bereq == "W-on-bereq" }

server s1 -start

varnish v1 -vcl+backend { sub vcl_recv { set req.http.To-Read = "R-from-req"; return (pipe); }

sub vcl_pipe {

write to req

set req.http.W-Req = "W-on-req";

read from req

set bereq.http.R-Req = req.http.To-Read;

write to bereq

set bereq.http.W-Bereq = "W-on-bereq";

read from bereq

set bereq.http.R-Bereq = bereq.http.W-Bereq; }

sub vcl_deliver { set obj.http.W-Obj = "W-on-obj"; }

} -start

client c1 { txreq rxresp } -run`

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fgsch/varnish3to4/pull/2#issuecomment-264834606, or mute the thread https://github.com/notifications/unsubscribe-auth/AAURXMFpkDDAH7PIU_St_f837nQLLcgNks5rE_mNgaJpZM4LDYVR .