Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

[Multipart] add test case with HttpPart #613

Merged
merged 22 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/lemon-fireants-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Add test case with `HttpPart` for multipart
120 changes: 97 additions & 23 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ Content-Type: multipart/form-data; boundary=abcde12345
Content-Disposition: form-data; name="profileImage"; filename="<any-name-is-ok>"
Content-Type: application/octet-stream;

{…file content…}
{…file content of .jpg file…}
--abcde12345--
```

Expand Down Expand Up @@ -2648,7 +2648,7 @@ Content-Type: text/plain
Content-Disposition: form-data; name="profileImage"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream;

{…file content…}
{…file content of .jpg file…}
--abcde12345--
```

Expand Down Expand Up @@ -2678,12 +2678,12 @@ Content-Type: text/plain
Content-Disposition: form-data; name="pictures"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .png file…}
--abcde12345
Content-Disposition: form-data; name="pictures"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .png file…}
--abcde12345--
```

Expand All @@ -2707,7 +2707,7 @@ Content-Type: text/plain
Content-Disposition: form-data; name="profileImage"; filename="hello.jpg"
Content-Type: image/jpg

{…file content…}
{…file content of .jpg file…}
--abcde12345--
```

Expand Down Expand Up @@ -2744,7 +2744,7 @@ Content-Type: application/json
Content-Disposition: form-data; name="profileImage"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .jpg file…}
--abcde12345--
Content-Disposition: form-data; name="previousAddresses"
Content-Type: application/json
Expand All @@ -2758,38 +2758,45 @@ Content-Type: application/json
Content-Disposition: form-data; name="pictures"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .png file…}
--abcde12345
Content-Disposition: form-data; name="pictures"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .png file…}
--abcde12345--
```

### Payload_MultiPart_FormData_jsonArrayParts
### Payload_MultiPart_FormData_complexWithHttpPart
msyyc marked this conversation as resolved.
Show resolved Hide resolved

- Endpoint: `post /multipart/form-data/json-array-parts`
- Endpoint: `post /multipart/form-data/complex-parts-with-httppart`

Expect request (

- according to https://datatracker.ietf.org/doc/html/rfc7578#section-4.4, content-type of file part shall be labeled with
appropriate media type, cadl-ranch will check it; content-type of other parts is optional, cadl-ranch will ignore it.
- according to https://datatracker.ietf.org/doc/html/rfc7578#section-4.2, filename of file part SHOULD be supplied.
If there are duplicated filename in same fieldName, cadl-ranch can't parse them all.
):
For File part, filename will not be checked but it is necessary otherwise cadl-ranch can't parse it;
content-type will be checked with value "application/octet-stream". Expect request:

```
POST /upload HTTP/1.1
Content-Length: 428
Content-Type: multipart/form-data; boundary=abcde12345

--abcde12345
Content-Disposition: form-data; name="profileImage"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream
Content-Disposition: form-data; name="id"
Content-Type: text/plain

{…file content…}
123
--abcde12345
Content-Disposition: form-data; name="address"
Content-Type: application/json

{
"city": "X"
}
--abcde12345
Content-Disposition: form-data; name="profileImage"; filename="<any-name-is-ok>"
Content-Type: application/octet-stream

{…file content of .jpg file…}
--abcde12345--
Content-Disposition: form-data; name="previousAddresses"
Content-Type: application/json

Expand All @@ -2798,6 +2805,73 @@ Content-Type: application/json
},{
"city": "Z"
}]
--abcde12345
Content-Disposition: form-data; name="pictures"; filename="<any-name-is-ok>"
Content-Type: application/octet-stream

{…file content of .png file…}
--abcde12345
Content-Disposition: form-data; name="pictures"; filename="<any-name-is-ok>"
Content-Type: application/octet-stream

{…file content of .png file…}
--abcde12345--
```

### Payload_MultiPart_FormData_fileWithHttpPartOptionalContentType

- Endpoint: `post /multipart/form-data/file-with-http-part-optional-content-type`

Please send request twice, first time with no content-type and second time with content-type "application/octet-stream". Expect request:

```
POST /upload HTTP/1.1
Content-Length: 428
Content-Type: multipart/form-data; boundary=abcde12345

--abcde12345
Content-Disposition: form-data; name="profileImage"; filename="<any-name-is-ok>"
Content-Type: application/octet-stream

{…file content of .jpg file…}
--abcde12345
```

### Payload_MultiPart_FormData_fileWithHttpPartRequiredContentType

- Endpoint: `post /multipart/form-data/check-filename-and-required-content-type-with-httppart`

This case will check required content-type of file part, so expect request:

```
POST /upload HTTP/1.1
Content-Length: 428
Content-Type: multipart/form-data; boundary=abcde12345

--abcde12345
Content-Disposition: form-data; name="profileImage"; filename="<any-name-is-ok>"
Content-Type: application/octet-stream

{…file content of .jpg file…}
--abcde12345--
```

### Payload_MultiPart_FormData_fileWithHttpPartSpecificContentType

- Endpoint: `post /multipart/form-data/check-filename-and-specific-content-type-with-httppart`

This case will check filename and specific content-type of file part, so expect request:

```
POST /upload HTTP/1.1
Content-Length: 428
Content-Type: multipart/form-data; boundary=abcde12345

--abcde12345
Content-Disposition: form-data; name="profileImage"; filename="hello.jpg"
Content-Type: image/jpg

{…file content of .jpg file…}
--abcde12345--
```

Expand Down Expand Up @@ -2829,7 +2903,7 @@ Content-Type: application/json
Content-Disposition: form-data; name="profileImage"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .jpg file…}
--abcde12345--
```

Expand All @@ -2854,12 +2928,12 @@ Content-Type: multipart/form-data; boundary=abcde12345
Content-Disposition: form-data; name="profileImage"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .jpg file…}
--abcde12345
Content-Disposition: form-data; name="picture"; filename="<any-or-no-name-is-ok>"
Content-Type: application/octet-stream

{…file content…}
{…file content of .png file…}
--abcde12345--
```

Expand Down
Loading
Loading