Skip to content

Add test for download gzip transport compression - #4345

Merged
bk2204 merged 1 commit into
git-lfs:masterfrom
bk2204:content-encoding
Dec 16, 2020
Merged

bk2204 merged 1 commit into
git-lfs:masterfrom
bk2204:content-encoding

Conversation

@bk2204

@bk2204 bk2204 commented Dec 14, 2020

Copy link
Copy Markdown
Member

Since we're uploading and downloading a large amount of data, we may prefer to use transport compression. Currently, Go will do this for us automatically unless we ask it not to. Let's detect this case and add a trace output so people can find it and we can add a test that it continues to work.

Note that it's not possible to detect this using the headers since Go adds the headers on the request and strips the headers on the response as part of making the request, so it's not readily apparent to users without this trace output.

Since we're uploading and downloading a large amount of data, we may
prefer to use transport compression.  Currently, Go will do this for us
automatically unless we ask it not to.  Let's detect this case and add a
trace output so people can find it and we can add a test that it
continues to work.

Note that it's not possible to detect this using the headers since Go
adds the headers on the request and strips the headers on the response
as part of making the request, so it's not readily apparent to users
without this trace output.
@bk2204
bk2204 requested a review from a team December 14, 2020 20:07

@chrisd8088 chrisd8088 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems all good to me, thank you!

@bk2204
bk2204 merged commit e95102b into git-lfs:master Dec 16, 2020
@bk2204
bk2204 deleted the content-encoding branch December 16, 2020 17:15
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Feb 26, 2026
In commit 44fae30 of PR git-lfs#4345 we added
the "storage upload with compression" test to our "t/t-push.sh" shell
test script in order to verify that when fetching Git LFS objects from
an HTTP service, we support gzip-encoded responses.

While this test is effective, its purpose differs from all the other
tests in the "t/t-push.sh" test script, since those are intended to
validate the action of the "git lfs push" command under various
circumstances.

The "storage upload with compression" test, by contrast, merely runs
the "git lfs push" command to establish its initial context.  It then
uses the "git lfs pull" command to verify the Git LFS client's handling
of a gzip-encoded object download.

As this test does not specifically check any aspect of the "git lfs push"
command's actions, we now extract it from the "t/t-push.sh" script into
a new test script named "t/t-batch-storage-encoding.sh".

This change provides a convenient location for any new tests we may
add in the future, should we introduce support for object downloads
encoded in other formats besides the gzip format.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Feb 26, 2026
In a prior commit in this PR we extracted the "storage upload with
compression" test from our "t/t-push.sh" shell test script into a
new "t/t-batch-storage-encoding.sh" script.

The original version of this test was first added in commit
44fae30 of PR git-lfs#4345, in order to
verify that the Git LFS client supports gzip-encoded responses to its
object download requests if they include an "Accept-Encoding: gzip"
header.

The test creates a single Git LFS object whose content is a special
string recognized by our "lfstest-gitserver" test utility, which then
performs distinct actions when responding to upload and download
requests for the object.

At present, this special key is the string "storage-compress", and when
an object with this value is uploaded or downloaded the test utility
checks that an "Accept-Encoding: gzip" header is present, and responds
with a 500 status code if not.  As well, when handling a download request
for an object with this value, the utility gzip-encodes the body of
the HTTP response and includes a "Content-Encoding: gzip" header.

While this specialized download request handling logic is necessary for
the "storage upload with compression" test to succeed, the upload request
handling logic is not, despite the name of the test.

In fact, the check for an "Accept-Encoding: gzip" request header in this
case serves no useful purpose, since the header is merely a notice to the
HTTP server that it may, if it chooses, send a gzip-encoded response body.
In particular, such a request header does not indicate that the request
body is encoded, so the "not encoded" error message our check would return
if the header was missing or lacked the value "gzip" is simply incorrect.

Further, by default the "net/http" package in the Go standard library
adds an "Accept-Encoding: gzip" header to all HTTP requests, so there
is little value to checking for the presence of that header in more than
one instance, and we already do so when handling the object download
made by the test.

We therefore remove the check for an "Accept-Encoding: gzip" header from
our object upload handling logic, which in turn allows us to rename the
special object content key from the generic term "storage-compress" to
the more specific term "storage-download-encoding-gzip".

As well, we rename the test from "storage upload with compression" to
"batch storage HTTP download with gzip encoding", which better reflects
its intent, and update the name of the repository created by the test
to match.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Feb 26, 2026
In prior commits in this PR we extracted the "storage upload with
compression" test from our "t/t-push.sh" shell test script into a
new "t/t-batch-storage-encoding.sh" script and then renamed the test
to "batch storage HTTP download with gzip encoding" to better reflect
its purpose.  (The original version of this test was first added in
commit 44fae30 of PR git-lfs#4345.)

We now update the test in several minor respects so it can serve as
a template for similar tests we may add in the future, should we
introduce support for object downloads encoded in other formats
besides the gzip format.

First, we reorganize and simplify the test's preliminary setup actions
to match our general idiom for tests of this type.  For instance,
since the test uses the "git lfs push" command simply to establish
its initial context, we can rely on that command to report any
unexpected failures and do not need to either capture its output into
a log file or call the assert_server_object() assertion function.
(If a regression was introduced to the "git lfs push" command, other
tests in our suite would detect this problem.)

Next, we simplify the test by replacing the "git clone" command
with a "git lfs pull" command.  Following a pattern we use in many
other tests, we delete the local Git LFS storage directories before
running the "git lfs pull" command so it will download the missing
object from our test server utility.

We then check the trace log output of the "git lfs pull" command
for the "decompressed gzipped response" message, which should only
appear if a gzip-encoded object download transfer took place.  This
is the test's key verification step, and was included with the original
version of the test in commit 44fae30,
at which time the trace log message was also introduced.

However, we would like this test to serve as a template for similar tests
we may add in the future, if we implement support for object downloads
encoded in other formats besides the gzip format.  With this goal in mind,
we expand the checks performed by the test in several ways.

As well as checking for the "decompressed gzipped response" trace log
message, we now also confirm that "Accept-Encoding: gzip" request headers
are captured in the log file.  In addition, we check that these headers
appear twice, once from the Git LFS Batch API request and once from the
subsequent object download request, and we check that the "decompressed
gzipped response" message appears only once, from the object download
request.

Finally, we add a number of comments to the test to help explicate
its function and the reasons why we expect two "Accept-Encoding: gzip"
request headers but only one "decompressed gzipped response" message
in the "git lfs pull" command's trace log output.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 1, 2026
In commit 44fae30 of PR git-lfs#4345 we added
the "storage upload with compression" test to our "t/t-push.sh" shell
test script in order to verify that when fetching Git LFS objects from
an HTTP service, we support gzip-encoded responses.

While this test is effective, its purpose differs from all the other
tests in the "t/t-push.sh" test script, since those are intended to
validate the action of the "git lfs push" command under various
circumstances.

The "storage upload with compression" test, by contrast, merely runs
the "git lfs push" command to establish its initial context.  It then
uses the "git lfs pull" command to verify the Git LFS client's handling
of a gzip-encoded object download.

As this test does not specifically check any aspect of the "git lfs push"
command's actions, we now extract it from the "t/t-push.sh" script into
a new test script named "t/t-batch-storage-encoding.sh".

This change provides a convenient location for any new tests we may
add in the future, should we introduce support for object downloads
encoded in other formats besides the gzip format.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 1, 2026
In a prior commit in this PR we extracted the "storage upload with
compression" test from our "t/t-push.sh" shell test script into a
new "t/t-batch-storage-encoding.sh" script.

The original version of this test was first added in commit
44fae30 of PR git-lfs#4345, in order to
verify that the Git LFS client supports gzip-encoded responses to its
object download requests if they include an "Accept-Encoding: gzip"
header.

The test creates a single Git LFS object whose content is a special
string recognized by our "lfstest-gitserver" test utility, which then
performs distinct actions when responding to upload and download
requests for the object.

At present, this special key is the string "storage-compress", and when
an object with this value is uploaded or downloaded the test utility
checks that an "Accept-Encoding: gzip" header is present, and responds
with a 500 status code if not.  As well, when handling a download request
for an object with this value, the utility gzip-encodes the body of
the HTTP response and includes a "Content-Encoding: gzip" header.

While this specialized download request handling logic is necessary for
the "storage upload with compression" test to succeed, the upload request
handling logic is not, despite the name of the test.

In fact, the check for an "Accept-Encoding: gzip" request header in this
case serves no useful purpose, since the header is merely a notice to the
HTTP server that it may, if it chooses, send a gzip-encoded response body.
In particular, such a request header does not indicate that the request
body is encoded, so the "not encoded" error message our check would return
if the header was missing or lacked the value "gzip" is simply incorrect.

Further, by default the "net/http" package in the Go standard library
adds an "Accept-Encoding: gzip" header to all HTTP requests, so there
is little value to checking for the presence of that header in more than
one instance, and we already do so when handling the object download
made by the test.

We therefore remove the check for an "Accept-Encoding: gzip" header from
our object upload handling logic, which in turn allows us to rename the
special object content key from the generic term "storage-compress" to
the more specific term "storage-download-encoding-gzip".

As well, we rename the test from "storage upload with compression" to
"batch storage HTTP download with gzip encoding", which better reflects
its intent, and update the name of the repository created by the test
to match.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 1, 2026
In prior commits in this PR we extracted the "storage upload with
compression" test from our "t/t-push.sh" shell test script into a
new "t/t-batch-storage-encoding.sh" script and then renamed the test
to "batch storage HTTP download with gzip encoding" to better reflect
its purpose.  (The original version of this test was first added in
commit 44fae30 of PR git-lfs#4345.)

We now update the test in several minor respects so it can serve as
a template for similar tests we may add in the future, should we
introduce support for object downloads encoded in other formats
besides the gzip format.

First, we reorganize and simplify the test's preliminary setup actions
to match our general idiom for tests of this type.  For instance,
since the test uses the "git lfs push" command simply to establish
its initial context, we can rely on that command to report any
unexpected failures and do not need to either capture its output into
a log file or call the assert_server_object() assertion function.
(If a regression was introduced to the "git lfs push" command, other
tests in our suite would detect this problem.)

Next, we simplify the test by replacing the "git clone" command
with a "git lfs pull" command.  Following a pattern we use in many
other tests, we delete the local Git LFS storage directories before
running the "git lfs pull" command so it will download the missing
object from our test server utility.

We then check the trace log output of the "git lfs pull" command
for the "decompressed gzipped response" message, which should only
appear if a gzip-encoded object download transfer took place.  This
is the test's key verification step, and was included with the original
version of the test in commit 44fae30,
at which time the trace log message was also introduced.

However, we would like this test to serve as a template for similar tests
we may add in the future, if we implement support for object downloads
encoded in other formats besides the gzip format.  With this goal in mind,
we expand the checks performed by the test in several ways.

As well as checking for the "decompressed gzipped response" trace log
message, we now also confirm that "Accept-Encoding: gzip" request headers
are captured in the log file.  In addition, we check that these headers
appear twice, once from the Git LFS Batch API request and once from the
subsequent object download request, and we check that the "decompressed
gzipped response" message appears only once, from the object download
request.

Finally, we add a number of comments to the test to help explicate
its function and the reasons why we expect two "Accept-Encoding: gzip"
request headers but only one "decompressed gzipped response" message
in the "git lfs pull" command's trace log output.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 2, 2026
In prior commits in this PR we introduced a new configuration option
named "lfs.httpDownloadEncoding", which may be set to either of the
values "gzip" or "zstd", with a default value of "gzip".

When our new option is not defined or is set to "gzip", the Git LFS
client simply follows its legacy behaviour when making object transfer
download requests over HTTP.  Specifically, the client should allow the
"net/http" package in the Go standard library to insert an
"Accept-Encoding: gzip" header into the requests, and if the server
chooses to respond with gzip-encoded data, the client should expect
the "net/http" package to automatically decode the body of the response.

A test of this legacy behaviour was first introduced in PR git-lfs#4345.
More recently, in PR git-lfs#6207, we created the "t/t-batch-storage-encoding.sh"
shell script and moved the test into that script, while also renaming
the test to "batch storage HTTP download with gzip encoding".

We now expand the test to verify that the client continues to behave
as it has previously when our new configuration option is explicitly
set to "gzip", either universally or for a specific URL.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 2, 2026
In prior commits in this PR we introduced a new configuration option
named "lfs.transfer.httpDownloadEncoding", which may be set to either
of the values "gzip" or "zstd", with a default value of "gzip".

When our new option is not defined or is set to "gzip", the Git LFS
client simply follows its legacy behaviour when making object transfer
download requests over HTTP.  Specifically, the client should allow the
"net/http" package in the Go standard library to insert an
"Accept-Encoding: gzip" header into the requests, and if the server
chooses to respond with gzip-encoded data, the client should expect
the "net/http" package to automatically decode the body of the response.

A test of this legacy behaviour was first introduced in PR git-lfs#4345.
More recently, in PR git-lfs#6207, we created the "t/t-batch-storage-encoding.sh"
shell script and moved the test into that script, while also renaming
the test to "batch storage HTTP download with gzip encoding".

In order for our test to detect that an object transfer download request
was gzip-encoded, in PR git-lfs#4345 we also updated the DoWithRedirect()
method of the Client structure in our "lfshttp" package.  The method
checks whether the "net/http" package has set the Uncompressed field
in the Response structure it returns, which would indicate that the
response body was gzip-encoded and that it has been decoded for us.

If the Uncompressed field is set, our DoWithRedirect() method outputs
a trace log message.  The test is then able to use the presence of
this message in the logs it captures from each "git lfs pull" command
to determine that the client received a gzip-encoded response to an
object transfer download request and handled it appropriately.

We would now like to include a similar check in the "batch storage
HTTP download with zstd encoding" test that we added to our
"t/t-batch-storage-encoding.sh" shell script in previous commits
in this PR.

This test verifies that the changes we have made in this PR work as
expected to implement support for zstd-encoded object HTTP downloads.
Specifically, when our new configuration option is set to the value
"zstd", the Git LFS client should send an "Accept-Encoding: zstd"
header with each object download request, and should decode the
response body appropriately if the server chooses to encode it using
the zstd algorithm.

We therefore update the download() method of the basicDownloadAdapter
structure in our "tq" package to output a trace log message when
processing a zstd-encoded response to an object transfer download
request.  We then update our "batch storage HTTP download with zstd
encoding" test to check for this message in the logs it captures from
each "git lfs pull" command.
chrisd8088 added a commit to mzr/git-lfs that referenced this pull request Apr 9, 2026
In prior commits in this PR we introduced a new configuration option
named "lfs.httpDownloadEncoding", which may be set to either of the
values "gzip" or "zstd", with a default value of "gzip".

When our new option is not defined or is set to "gzip", the Git LFS
client simply follows its legacy behaviour when making object transfer
download requests over HTTP.  Specifically, the client should allow the
"net/http" package in the Go standard library to insert an
"Accept-Encoding: gzip" header into the requests, and if the server
chooses to respond with gzip-encoded data, the client should expect
the "net/http" package to automatically decode the body of the response.

A test of this legacy behaviour was first introduced in PR git-lfs#4345.
More recently, in PR git-lfs#6207, we created the "t/t-batch-storage-encoding.sh"
shell script and moved the test into that script, while also renaming
the test to "batch storage HTTP download with gzip encoding".

We now expand the test to verify that the client continues to behave
as it has previously when our new configuration option is explicitly
set to "gzip", either universally or for a specific URL.
chrisd8088 added a commit to mzr/git-lfs that referenced this pull request Apr 9, 2026
In prior commits in this PR we introduced a new configuration option
named "lfs.transfer.httpDownloadEncoding", which may be set to either
of the values "gzip" or "zstd", with a default value of "gzip".

When our new option is not defined or is set to "gzip", the Git LFS
client simply follows its legacy behaviour when making object transfer
download requests over HTTP.  Specifically, the client should allow the
"net/http" package in the Go standard library to insert an
"Accept-Encoding: gzip" header into the requests, and if the server
chooses to respond with gzip-encoded data, the client should expect
the "net/http" package to automatically decode the body of the response.

A test of this legacy behaviour was first introduced in PR git-lfs#4345.
More recently, in PR git-lfs#6207, we created the "t/t-batch-storage-encoding.sh"
shell script and moved the test into that script, while also renaming
the test to "batch storage HTTP download with gzip encoding".

In order for our test to detect that an object transfer download request
was gzip-encoded, in PR git-lfs#4345 we also updated the DoWithRedirect()
method of the Client structure in our "lfshttp" package.  The method
checks whether the "net/http" package has set the Uncompressed field
in the Response structure it returns, which would indicate that the
response body was gzip-encoded and that it has been decoded for us.

If the Uncompressed field is set, our DoWithRedirect() method outputs
a trace log message.  The test is then able to use the presence of
this message in the logs it captures from each "git lfs pull" command
to determine that the client received a gzip-encoded response to an
object transfer download request and handled it appropriately.

We would now like to include a similar check in the "batch storage
HTTP download with zstd encoding" test that we added to our
"t/t-batch-storage-encoding.sh" shell script in previous commits
in this PR.

This test verifies that the changes we have made in this PR work as
expected to implement support for zstd-encoded object HTTP downloads.
Specifically, when our new configuration option is set to the value
"zstd", the Git LFS client should send an "Accept-Encoding: zstd"
header with each object download request, and should decode the
response body appropriately if the server chooses to encode it using
the zstd algorithm.

We therefore update the download() method of the basicDownloadAdapter
structure in our "tq" package to output a trace log message when
processing a zstd-encoded response to an object transfer download
request.  We then update our "batch storage HTTP download with zstd
encoding" test to check for this message in the logs it captures from
each "git lfs pull" command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants