Skip to content

Commit dbf3c69

Browse files
committed
http: support upper case methods for POST/PUT
1 parent 9a260b5 commit dbf3c69

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

fsspec/implementations/http.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,14 @@ async def gen_chunks():
275275
kw = self.kwargs.copy()
276276
kw.update(kwargs)
277277
session = await self.set_session()
278-
meth = getattr(session, method)
279278

279+
method = method.lower()
280+
if method not in ("post", "put"):
281+
raise ValueError(
282+
f"method has to be either 'post' or 'put', not: {method!r}"
283+
)
284+
285+
meth = getattr(session, method)
280286
async with meth(lpath, data=gen_chunks(), **kw) as resp:
281287
self._raise_not_found_for_status(resp, lpath)
282288

fsspec/implementations/tests/test_http.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import threading
66
import time
7+
from collections import ChainMap
78
from http.server import BaseHTTPRequestHandler, HTTPServer
89

910
import pytest
@@ -25,12 +26,15 @@
2526

2627

2728
class HTTPTestHandler(BaseHTTPRequestHandler):
28-
files = {
29+
static_files = {
2930
"/index/realfile": data,
3031
"/index/otherfile": data,
3132
"/index": index,
3233
"/data/20020401": listing,
3334
}
35+
dynamic_files = {}
36+
37+
files = ChainMap(dynamic_files, static_files)
3438

3539
def __init__(self, *args, **kwargs):
3640
super().__init__(*args, **kwargs)
@@ -81,6 +85,8 @@ def do_POST(self):
8185
self.files[file_path] = self.rfile.read(length)
8286
self._respond(200)
8387

88+
do_PUT = do_POST
89+
8490
def read_chunks(self):
8591
length = -1
8692
while length != 0:
@@ -142,6 +148,15 @@ def server():
142148
yield s
143149

144150

151+
@pytest.fixture
152+
def reset_files():
153+
yield
154+
155+
# Reset the newly added files after the
156+
# test is completed.
157+
HTTPTestHandler.dynamic_files.clear()
158+
159+
145160
def test_list(server):
146161
h = fsspec.filesystem("http")
147162
out = h.glob(server + "/index/*")
@@ -432,7 +447,8 @@ def test_info(server):
432447
assert info["ETag"] == "xxx"
433448

434449

435-
def test_put_file(server, tmp_path):
450+
@pytest.mark.parametrize("method", ["POST", "PUT"])
451+
def test_put_file(server, tmp_path, method, reset_files):
436452
src_file = tmp_path / "file_1"
437453
src_file.write_bytes(data)
438454

@@ -442,7 +458,7 @@ def test_put_file(server, tmp_path):
442458
with pytest.raises(FileNotFoundError):
443459
fs.info(server + "/hey")
444460

445-
fs.put_file(src_file, server + "/hey")
461+
fs.put_file(src_file, server + "/hey", method=method)
446462
assert fs.info(server + "/hey")["size"] == len(data)
447463

448464
fs.get_file(server + "/hey", dwl_file)

0 commit comments

Comments
 (0)