[PR #35] [MERGED] Add optional custom external URL #284

Closed
opened 2026-03-03 12:10:05 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fsouza/fake-gcs-server/pull/35
Author: @jwhitlock
Created: 6/5/2019
Status: Merged
Merged: 6/8/2019
Merged by: @fsouza

Base: masterHead: custom-external-url


📝 Commits (1)

  • 77618f5 Add optional custom external URL

📊 Changes

2 files changed (+29 additions, -5 deletions)

View changed files

📝 fakestorage/server.go (+16 -5)
📝 fakestorage/server_test.go (+13 -0)

📄 Description

Add the ability to specify a different base server URL. This would be used by https://github.com/teone/gc-fake-storage to customize the Location header for resumable uploads.

When I use the Python client to upload a large file to gc-fake-storage, it uses the resumable upload endpoint, which is supported by fake-gcs-server 🎉 . The raw request, to gc-fake-storage running in a Docker container called gcs-emulator on port 4443, looks something like this:

POST /upload/storage/v1/bucket_name/o?uploadType=resumable 
HTTP/1.1
Host: gcs-emulator:4443
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
content-type: application/json; charset=UTF-8
x-upload-content-type: text/plain
Content-Length: 236

{"name": "v1/file.bin/file.bin/8D1AEB53DC42444C8C46ABD7FD697AFD/file.bin", "contentType": "text/plain", "metadata": {"original_size": "369412", "original_md5_hash": "8d1aeb53dc42444c8c46abd7fd697afd"}, "contentEncoding": "gzip"}'

gc-fake-storage serves on 0.0.0.0:4443 inside the Docker container, and the raw response looks like:

HTTP/1.1 200 OK

Location: https://[::]:4443/upload/resumable/c3acc487c6f5a58295bb058a2099f88c
Date: Tue, 04 Jun 2019 22:06:16 GMT
Content-Length: 82
Content-Type: text/plain; charset=utf-8

[::] is the IPv6 equivalent shorthand for IPv4's 0.0.0.0. The Python client attempts to POST the first chunk of the file to the Location URL, but that is on the requester's container, not the gc-fake-server container, and the request fails.

In order for this to work, the Location header would need to be:

Location: https://gc-fake-storage:4443/upload/resumable/c3acc487c6f5a58295bb058a2099f88c

This PR adds a way to customize what Server.URL() returns, which can eventually be used in gc-fake-storage to set the external-facing domain for resumable uploads.

I also considered dropping the domain name from the resumable upload response, so the Location header looks like:

Location: /upload/resumable/c3acc487c6f5a58295bb058a2099f88c

This may also work, but causes tests to fail if done unconditionally. A similar option could be used to drop the domain if requested.

A third option is to use the Host from the request, but this also breaks tests.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fsouza/fake-gcs-server/pull/35 **Author:** [@jwhitlock](https://github.com/jwhitlock) **Created:** 6/5/2019 **Status:** ✅ Merged **Merged:** 6/8/2019 **Merged by:** [@fsouza](https://github.com/fsouza) **Base:** `master` ← **Head:** `custom-external-url` --- ### 📝 Commits (1) - [`77618f5`](https://github.com/fsouza/fake-gcs-server/commit/77618f59d5c5718aab3e8915989c02833537a1ad) Add optional custom external URL ### 📊 Changes **2 files changed** (+29 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `fakestorage/server.go` (+16 -5) 📝 `fakestorage/server_test.go` (+13 -0) </details> ### 📄 Description Add the ability to specify a different base server URL. This would be used by https://github.com/teone/gc-fake-storage to customize the ``Location`` header for resumable uploads. When I use the Python client to upload a large file to ``gc-fake-storage``, it uses the resumable upload endpoint, which is supported by ``fake-gcs-server`` 🎉 . The raw request, to ``gc-fake-storage`` running in a Docker container called ``gcs-emulator`` on port 4443, looks something like this: ``` POST /upload/storage/v1/bucket_name/o?uploadType=resumable HTTP/1.1 Host: gcs-emulator:4443 User-Agent: python-requests/2.22.0 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive content-type: application/json; charset=UTF-8 x-upload-content-type: text/plain Content-Length: 236 {"name": "v1/file.bin/file.bin/8D1AEB53DC42444C8C46ABD7FD697AFD/file.bin", "contentType": "text/plain", "metadata": {"original_size": "369412", "original_md5_hash": "8d1aeb53dc42444c8c46abd7fd697afd"}, "contentEncoding": "gzip"}' ``` ``gc-fake-storage`` serves on ``0.0.0.0:4443`` inside the Docker container, and the raw response looks like: ``` HTTP/1.1 200 OK Location: https://[::]:4443/upload/resumable/c3acc487c6f5a58295bb058a2099f88c Date: Tue, 04 Jun 2019 22:06:16 GMT Content-Length: 82 Content-Type: text/plain; charset=utf-8 ``` ``[::]`` is the IPv6 equivalent shorthand for IPv4's ``0.0.0.0``. The Python client attempts to ``POST`` the first chunk of the file to the ``Location`` URL, but that is on the requester's container, not the ``gc-fake-server`` container, and the request fails. In order for this to work, the ``Location`` header would need to be: ``` Location: https://gc-fake-storage:4443/upload/resumable/c3acc487c6f5a58295bb058a2099f88c ``` This PR adds a way to customize what ``Server.URL()`` returns, which can eventually be used in ``gc-fake-storage`` to set the external-facing domain for resumable uploads. I also considered dropping the domain name from the resumable upload response, so the ``Location`` header looks like: ``` Location: /upload/resumable/c3acc487c6f5a58295bb058a2099f88c ``` This may also work, but causes tests to fail if done unconditionally. A similar option could be used to drop the domain if requested. A third option is to use the ``Host`` from the request, but this also breaks tests. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 12:10:05 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#284
No description provided.