Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,16 @@ func TestHTTPClientWithSelfSignedCertificate(t *testing.T) {
)

// init test (self-signed) HTTPS endpoint
server := newTestImageServer(t, http.StatusOK)
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fileBytes, err := os.ReadFile(path.Join("testdata", "image.svg"))
if err != nil {
t.Fatal(err)
}

w.Header().Set("Content-Type", "image/svg+xml")
w.WriteHeader(http.StatusOK)
w.Write(fileBytes)
}))
Comment thread
NGTmeaty marked this conversation as resolved.
Outdated
defer server.Close()

// init the HTTP client responsible for recording HTTP(s) requests / responses
Expand Down
31 changes: 31 additions & 0 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,29 @@ func (d *customDialer) writeWARCFromConnection(ctx context.Context, reqPipe, res
slices.Reverse(batch.Records)
}

var selectedCipherSuite string
var selectedProtocol string

if cc, ok := conn.(*tls.UConn); ok {
state := cc.ConnectionState()
// Use tls.CipherSuiteName for efficient lookup
selectedCipherSuite = tls.CipherSuiteName(state.CipherSuite)
// Add the negotiated protocol version
// Values as defined in WARC proposal https://github.com/iipc/warc-specifications/issues/42
switch state.Version {
case tls.VersionSSL30:
selectedProtocol = "ssl/3"
case tls.VersionTLS10:
selectedProtocol = "tls/1.0"
case tls.VersionTLS11:
selectedProtocol = "tls/1.1"
case tls.VersionTLS12:
selectedProtocol = "tls/1.2"
case tls.VersionTLS13:
selectedProtocol = "tls/1.3"
}
Comment on lines +507 to +518
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to writing a WARC-Protocol value for the encryption used, it could be nice to add support for which HTTP verison was archived to have feature parity with wget-lua:

- http/0.9
- http/1.0
- http/1.1

Not a request for right now, but noted all the same

}

var warcTargetURI string
select {
case recv, ok := <-targetURIRespCh:
Expand All @@ -521,6 +544,14 @@ func (d *customDialer) writeWARCFromConnection(ctx context.Context, reqPipe, res

r.Header.Set("WARC-Record-ID", "<urn:uuid:"+recordIDs[i]+">")

if selectedCipherSuite != "" {
r.Header.Set("WARC-Cipher-Suite", selectedCipherSuite)
}

if selectedProtocol != "" {
r.Header.Set("WARC-Protocol", selectedProtocol)
}

if i == len(recordIDs)-1 {
r.Header.Set("WARC-Concurrent-To", "<urn:uuid:"+recordIDs[0]+">")
} else {
Expand Down
Loading