Skip to content

Commit

Permalink
WIP: Debugging Trafficserver upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Jan 31, 2025
1 parent f678fd3 commit d6ab4f0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 17 deletions.
7 changes: 6 additions & 1 deletion templates/etc/test-env/nginx/apis.conf.etlua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ server {

local upload_size = 0
local chunk_size = 4096
local form = upload:new(chunk_size)
local form, form_err = upload:new(chunk_size)
if not form then
ngx.log(ngx.ERR, "new upload failed: ", form_err)
ngx.exit(500)
end

while true do
local typ, res, err = form:read()
if typ == "body" then
Expand Down
14 changes: 11 additions & 3 deletions templates/etc/trafficserver/records.yaml.etlua
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ records:
warning: E

# Enable for debug logging.
# debug:
# enabled: 1
# tags: ".*"
debug:
enabled: 1
# tags: ".*"
tags: "http_hdrs|http_tproxy|http_trans"

error:
logfile:
Expand Down Expand Up @@ -92,6 +93,11 @@ records:
sock_option_flag_out: 3

http:
# request_buffer_enabled: 0
# post_copy_size: 100M
# keep_alive_post_out: 0
# max_post_size: "1000000"

server_ports: <%- json_encode(config["trafficserver"]["port"]) %>

# Increase timeouts to match the timeouts in other pieces of the stack.
Expand Down Expand Up @@ -167,6 +173,8 @@ records:
# Don't perform caching when the request contains cookies.
cache_responses_to_cookies: 0

post_method: 0

cache:
ram_cache:
size: <%- json_encode(config["trafficserver"]["records"]["cache"]["ram_cache"]["size"]) %>
Expand Down
12 changes: 8 additions & 4 deletions test/apis/test_web_app_large_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ def test_fails_with_large_body_above_default_limit
assert_operator(body.bytesize, :>, 1 * 1024 * 1024) # 1MB
assert_operator(body.bytesize, :<, 1.1 * 1024 * 1024) # 1.1MB

response = Typhoeus.put("https://127.0.0.1:9081/api-umbrella/v1/users/#{user.id}.json", http_options.deep_merge(admin_token).deep_merge({
:headers => { "Content-Type" => "application/json" },
:body => body,
}))
response = nil
100.times do
response = Typhoeus.post("https://127.0.0.1:9081/api-umbrella/v1/users/#{user.id}.json", http_options.deep_merge(admin_token).deep_merge({
:headers => { "Content-Type" => "application/json" },
:body => body,
}))
ap response.code
end
assert_response_code(413, response)

user.reload
Expand Down
93 changes: 84 additions & 9 deletions test/proxy/test_uploads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,102 @@

class Test::Proxy::TestUploads < Minitest::Test
include ApiUmbrellaTestHelpers::Setup
parallelize_me!
# parallelize_me!

def setup
super
setup_server
end

def test_large_uploads
def test_no_multipart_post_request_body_size_limit
file_size = 20 * 1024 * 1024 # 20MB
with_file_of_size(file_size) do |file|
response = Typhoeus.post("http://127.0.0.1:9080/api/upload", http_options.deep_merge({
:body => { :upload => file },
}))

assert_response_code(200, response)
data = MultiJson.load(response.body)
assert_equal(file_size, data["upload_size"])
end
end

def test_no_post_request_body_size_limit
file_size = 20 * 1024 * 1024 # 20MB
with_file_of_size(file_size) do |file|
response = Typhoeus.post("http://127.0.0.1:9080/api/info/?post", http_options.deep_merge({
:body => file.read,
}))

assert_response_code(200, response)
data = MultiJson.load(response.body)
assert_equal(file_size, data.fetch("headers").fetch("content-length").to_i)
end
end

def test_no_put_request_body_size_limit
file_size = 20 * 1024 * 1024 # 20MB
with_file_of_size(file_size) do |file|
# 100.times do
1.times do
file.rewind
response = Typhoeus.put("http://127.0.0.1:9080/api/info/?put", http_options.deep_merge({
:body => file.read,
}))

assert_response_code(200, response)
data = MultiJson.load(response.body)
assert_equal(file_size, data.fetch("headers").fetch("content-length").to_i)
end
end
end

def test_no_patch_request_body_size_limit
file_size = 20 * 1024 * 1024 # 20MB
with_file_of_size(file_size) do |file|
# 100.times do
1.times do
file.rewind
response = Typhoeus.patch("http://127.0.0.1:9080/api/info/?patch", http_options.deep_merge({
:body => file.read,
}))

assert_response_code(200, response)
data = MultiJson.load(response.body)
assert_equal(file_size, data.fetch("headers").fetch("content-length").to_i)
end
end
end

def test_no_get_request_body_size_limit
file_size = 20 * 1024 * 1024 # 20MB
with_file_of_size(file_size) do |file|
# 100.times do
1.times do
file.rewind
response = Typhoeus.get("http://127.0.0.1:9080/api/info/?get", http_options.deep_merge({
:body => file.read,
}))

assert_response_code(200, response)
data = MultiJson.load(response.body)
assert_equal(file_size, data.fetch("headers").fetch("content-length").to_i)
end
end
end

private

def with_file_of_size(file_size)
file_size = 20 * 1024 * 1024 # 20MB
file = Tempfile.new("large")
chunk_size = 1024 * 1024
chunks = file_size / chunk_size
chunks.times { file.write(SecureRandom.random_bytes(chunk_size)) }
file.flush
file.rewind

response = Typhoeus.post("http://127.0.0.1:9080/api/upload", http_options.deep_merge({
:body => { :upload => file },
}))

assert_response_code(200, response)
data = MultiJson.load(response.body)
assert_equal(file_size, data["upload_size"])
yield file
ensure
file.close
file.unlink
Expand Down

0 comments on commit d6ab4f0

Please sign in to comment.