Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequestContent #21320

Merged
merged 35 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fa44787
Prototype for RequestContent
alzimmermsft May 11, 2021
fa4171d
Additional implementations of RequestContent
alzimmermsft May 12, 2021
0c75878
Add RequestOutbound implementations to HTTP client libraries
alzimmermsft May 12, 2021
ba65d71
Merge branch 'master' into AzCore_RequestContent
alzimmermsft May 14, 2021
929aa54
Add asFluxByteBuffer to RequestContent
alzimmermsft May 15, 2021
ef8ff2c
Merge branch 'master' into AzCore_RequestContent
alzimmermsft May 18, 2021
d76af17
Updates to RequestContent and move OkHttp to using RequestContent#wri…
alzimmermsft May 19, 2021
489a467
Merge branch 'master' into AzCore_RequestContent
alzimmermsft May 28, 2021
184bcb9
Fix Netty testing error
alzimmermsft May 28, 2021
7639d51
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 1, 2021
0283bc0
Updates to sending OkHttp requests
alzimmermsft Jun 1, 2021
8e881db
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 1, 2021
f51d356
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 2, 2021
67f6e82
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 3, 2021
1fcf77a
Removed writeTo, added BufferedByteBufferFlux
alzimmermsft Jun 3, 2021
91d3ba2
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 3, 2021
75a6059
Add RequestContent tests
alzimmermsft Jun 3, 2021
86cb04d
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 3, 2021
34f47ba
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 4, 2021
077d1ed
Add factory methods for InputStream RequestContent
alzimmermsft Jun 4, 2021
443643c
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 7, 2021
f99b4ff
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 8, 2021
9ecfb53
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 9, 2021
95b75ef
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 10, 2021
bf1898b
Make RequestContent an abstract class instead of interface
alzimmermsft Jun 10, 2021
871a299
Merge branch 'master' into AzCore_RequestContent
alzimmermsft Jun 16, 2021
80a3c8d
Cache the serialized object
alzimmermsft Jun 16, 2021
645c0fc
Fix linting issues
alzimmermsft Jun 16, 2021
7b70698
Merge branch 'main' into AzCore_RequestContent
alzimmermsft Jun 21, 2021
d2739fa
Merge branch 'main' into AzCore_RequestContent
alzimmermsft Jun 24, 2021
fcd70dc
Hide some APIs, added more tests
alzimmermsft Jun 24, 2021
49665ed
Merge branch 'main' into AzCore_RequestContent
alzimmermsft Jun 25, 2021
d7b4a97
Doc updates and PR feedback
alzimmermsft Jun 25, 2021
b23308d
Overloads to configure chunkSize
alzimmermsft Jun 25, 2021
d4bc387
Remove some overloads
alzimmermsft Jun 26, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.implementation.util;

import com.azure.core.util.RequestContent;
import com.azure.core.util.RequestOutbound;
import reactor.core.publisher.Mono;

/**
* A {@link RequestContent} implementation which is backed by a {@code byte[]}.
*/
public final class ArrayContent extends RequestContent {
private final byte[] content;
private final int offset;
private final int length;

public ArrayContent(byte[] content, int offset, int length) {
this.content = content;
this.offset = offset;
this.length = length;
}

@Override
public Mono<Void> writeToAsync(RequestOutbound requestOutbound) {
return Mono.defer(() -> Mono.fromRunnable(() -> writeTo(requestOutbound)));
}

@Override
public void writeTo(RequestOutbound requestOutbound) {

}

@Override
public Long attemptToGetLength() {
return (long) length;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/**
* Package containing implementation utilities.
*/
package com.azure.core.implementation.util;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.util;

import com.azure.core.implementation.util.ArrayContent;
import com.azure.core.util.serializer.ObjectSerializer;
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

/**
* Represents the content sent as part of a request.
*/
public abstract class RequestContent {
/**
* Write the {@link RequestContent} to the {@link RequestOutbound}.
*
* @param requestOutbound The outbound where the request will be written.
* @return An asynchronous response which will emit once the request has completed writing.
*/
public abstract Mono<Void> writeToAsync(RequestOutbound requestOutbound);

/**
* Write the {@link RequestContent} to the {@link RequestOutbound}.
*
* @param requestOutbound The outbound where the request will be written.
*/
public abstract void writeTo(RequestOutbound requestOutbound);

/**
* Gets the length of the {@link RequestContent}, if it is able to be calculated.
*
* @return The length of the {@link RequestContent}, if it is able to be calculated.
*/
public abstract Long attemptToGetLength();
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a {@link RequestContent} comprised of the {@code bytes}.
*
* @param bytes The bytes that will be the {@link RequestContent} data.
* @return A new {@link RequestContent}.
*/
public static RequestContent create(byte[] bytes) {
Objects.requireNonNull(bytes, "'bytes' cannot be null.");
return create(bytes, 0, bytes.length);
}

/**
* Creates a {@link RequestContent} comprised of the {@code bytes}.
*
* @param bytes The bytes that will be the {@link RequestContent} data.
* @param offset Offset in the bytes where the data will begin.
* @param length Length of the data.
* @return A new {@link RequestContent}.
*/
public static RequestContent create(byte[] bytes, int offset, int length) {
Objects.requireNonNull(bytes, "'bytes' cannot be null.");
return new ArrayContent(bytes, offset, length);
}

/**
* Creates a {@link RequestContent} comprised of the {@code content}.
*
* @param content
* @return
*/
public static RequestContent create(String content) {
return create(content.getBytes(StandardCharsets.UTF_8));
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
}

/**
*
* @param content
* @return
*/
public static RequestContent create(BinaryData content) {
return create(content.toBytes());
}

/**
*
* @param serializable
* @return
*/
public static RequestContent create(Object serializable) {
return create(serializable, null);
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
}

/**
*
* @param serializable
* @param serializer
* @return
*/
public static RequestContent create(Object serializable, ObjectSerializer serializer) {
return create(serializer.serializeToBytes(serializable));
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.util;

public class RequestOutbound {
}