Skip to content

Commit 64037d8

Browse files
committed
fix: nil on reqbuilder and docs on hdrs tab
1 parent f157cbb commit 64037d8

File tree

6 files changed

+78
-73
lines changed

6 files changed

+78
-73
lines changed

assets/static/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ a:hover {
496496
}
497497

498498
.strike {
499-
text-decoration: line-through;
499+
text-decoration: line-through !important;
500500
}
501501

502502
div.headers {

pkg/server/templates/content/tab_headers.templ

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package content
22

33
import (
4-
"github.com/aorith/varnishlog-parser/vsl"
54
"log"
5+
"fmt"
6+
7+
"github.com/aorith/varnishlog-parser/vsl"
68
)
79

810
func HeadersTab(txsSet vsl.TransactionSet) templ.Component {
@@ -12,26 +14,27 @@ func HeadersTab(txsSet vsl.TransactionSet) templ.Component {
1214
templ headersTab(txsSet vsl.TransactionSet) {
1315
<div id="tabHeaders" class="tabcontent">
1416
<p>
15-
This tab displays the state of HTTP headers, organized into transaction groups.
16-
For each transaction of type "request" or "backend request," four tables show the state of the headers.
17+
This tab displays the state of HTTP headers, grouped by transaction.
18+
For each transaction of type <code>request</code> or <code>backend request</code>,
19+
a table shows the headers as they were initially received and how they changed after VCL processing.
1720
</p>
18-
<p>Headers have four states:</p>
21+
<p>Headers are categorized into four states:</p>
1922
<table class="headers-legend">
2023
<tr>
21-
<th class="diffOriginal">Original:</th>
22-
<td>Headers present before any VCL processing, as initially sent by the client.</td>
24+
<th class="diffOriginal">Received</th>
25+
<td>Headers present before any VCL processing, as originally received.</td>
2326
</tr>
2427
<tr>
25-
<th class="diffModified">Modified:</th>
26-
<td>Headers that originated from the client but were subsequently modified in VCL.</td>
28+
<th class="diffAdded">Added</th>
29+
<td>Headers introduced by VCL that were not part of the originally received set.</td>
2730
</tr>
2831
<tr>
29-
<th class="diffDeleted">Deleted:</th>
30-
<td>Original headers that have been removed during VCL processing.</td>
32+
<th class="diffModified">Modified</th>
33+
<td>Headers that were present in the received set but were later changed by VCL.</td>
3134
</tr>
3235
<tr>
33-
<th class="diffAdded">Added:</th>
34-
<td>New headers introduced by VCL that were not part of the original request.</td>
36+
<th class="diffDeleted strike">Deleted</th>
37+
<td>Headers that were removed at any point during processing.</td>
3538
</tr>
3639
</table>
3740
<br/>
@@ -59,11 +62,16 @@ func renderHeaderTree(tx *vsl.Transaction, visited map[string]bool) (comps []tem
5962
}
6063
visited[tx.TXID()] = true
6164

62-
reqName := "ReqHeader"
63-
respName := "RespHeader"
65+
var (
66+
reqName string
67+
respName string
68+
)
6469
if tx.Type() == vsl.TxTypeBereq {
65-
reqName = "BereqHeader"
66-
respName = "BerespHeader"
70+
reqName = fmt.Sprintf("BereqHeader (%s)", tx.TXID())
71+
respName = fmt.Sprintf("BerespHeader (%s)", tx.TXID())
72+
} else if tx.Type() == vsl.TxTypeRequest {
73+
reqName = fmt.Sprintf("ReqHeader (%s)", tx.TXID())
74+
respName = fmt.Sprintf("RespHeader (%s)", tx.TXID())
6775
}
6876

6977
for _, r := range tx.LogRecords() {
@@ -101,9 +109,7 @@ templ renderTxHeaderTree(tx *vsl.Transaction, headers vsl.Headers, hdrTitle stri
101109
{{ numValues := max(len(received), len(processed)) }}
102110
for i := 0; i < numValues; i++ {
103111
<tr>
104-
if i == 0 {
105-
<th class="hdrname" rowspan="{ maxRows }">{ h.Name() }</th>
106-
}
112+
<th class="hdrname">{ h.Name() }</th>
107113
if i < len(received) {
108114
@renderHeader(received[i].Value(), getHeaderDiffAttrs(received[i].State()))
109115
} else {
@@ -134,7 +140,7 @@ func getHeaderDiffAttrs(state vsl.HdrState) templ.Attributes {
134140
case vsl.HdrStateModified:
135141
return templ.Attributes{"class": "diffModified"}
136142
case vsl.HdrStateDeleted:
137-
return templ.Attributes{"class": "diffDeleted"}
143+
return templ.Attributes{"class": "diffDeleted strike"}
138144
}
139145
return templ.Attributes{"class": "diffOriginal"}
140146
}

pkg/server/templates/content/tab_headers_templ.go

Lines changed: 36 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/templates/content/tab_reqbuilder.templ

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type ReqBuilderForm struct {
1818

1919
templ ReqBuilderTab(txsSet vsl.TransactionSet) {
2020
<div id="tabRequest" class="tabcontent">
21-
<p>Here you can generate commands with <a href="https://curl.se/" target="_blank">curl</a> and other tools based on parsed VSL transaction tags. For POST/PUT requests, <b>body is not available</b> in varnishlog and won’t be included.</p>
21+
<p>Generate <a href="https://curl.se/" target="_blank">curl</a> commands directly from parsed VSL transaction data. Note that for POST and PUT requests, the request body is not recorded by <code>varnishlog</code> and therefore cannot be included.</p>
2222
<form
2323
class="simple-form"
2424
hx-post="reqbuilder/"
@@ -76,7 +76,7 @@ templ ReqBuilderTab(txsSet vsl.TransactionSet) {
7676
<select id="transactionBackend" name="transactionBackend">
7777
for _, tx := range txsSet.Transactions() {
7878
if tx.Type() == vsl.TxTypeBereq {
79-
<option value={ getBackend(tx) }>{ tx.TXID() } ({ getBackend(tx) })</option>
79+
<option value={ getBackendConnStr(tx) }>{ tx.TXID() } ({ getBackendConnStr(tx) })</option>
8080
}
8181
}
8282
</select>
@@ -119,9 +119,8 @@ func curlCommand(tx *vsl.Transaction, f ReqBuilderForm) string {
119119
backend = nil
120120
case "auto":
121121
if tx.Type() == vsl.TxTypeBereq {
122-
br := tx.RecordByTag(tag.BackendOpen, false)
123-
bo := br.(vsl.BackendOpenRecord)
124-
host, port, err := render.ParseBackend(fmt.Sprintf("%s:%d", bo.RemoteAddr().String(), bo.RemotePort()))
122+
backendConn := getBackendConnStr(tx)
123+
host, port, err := render.ParseBackend(backendConn)
125124
if err != nil {
126125
return "error parsing backend: " + err.Error()
127126
}
@@ -153,7 +152,7 @@ func curlCommand(tx *vsl.Transaction, f ReqBuilderForm) string {
153152
return httpReq.CurlCommand(f.Scheme, backend)
154153
}
155154

156-
func getBackend(t *vsl.Transaction) string {
155+
func getBackendConnStr(t *vsl.Transaction) string {
157156
r := t.RecordByTag(tag.BackendOpen, true)
158157
if r == nil {
159158
return "none"

0 commit comments

Comments
 (0)