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

Update URI encoding to support URL.RawPath consistently #433

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ private GoWriter.Writable generateClientContextParamInitialization(
};
}

private static String getAddEndpointMiddlewareFuncName(String operationName) {
public static String getAddEndpointMiddlewareFuncName(String operationName) {
return String.format("add%sResolveEndpointMiddleware", operationName);
}


private static String getMiddlewareObjectName(String operationName) {
public static String getMiddlewareObjectName(String operationName) {
return String.format("op%sResolveEndpointMiddleware", operationName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,20 @@ private void generateOperationSerializerMiddleware(GenerationContext context, Op
writer.write("");
writer.write("opPath, opQuery := httpbinding.SplitURI($S)", httpTrait.getUri());
writer.write("request.URL.Path = smithyhttp.JoinPath(request.URL.Path, opPath)");
writer.write("""
if request.URL.RawPath != "" {
request.URL.RawPath = smithyhttp.JoinPath(request.URL.RawPath, opPath)
}
""");
writer.write("request.URL.RawQuery = smithyhttp.JoinRawQuery(request.URL.RawQuery, opQuery)");
writer.write("request.Method = $S", httpTrait.getMethod());
writer.write("restEncoder, err := httpbinding.NewEncoder(request.URL.Path, request.URL.RawQuery, "
+ "request.Header)");
writer.write("""
restEncoder, err := httpbinding.NewEncoder(
request.URL.Path,
request.URL.RawPath,
request.URL.RawQuery,
request.Header)
""");
writer.openBlock("if err != nil {", "}", () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void generateOperationSerializer(GenerationContext context, OperationSha
}""");
writer.write("request.Request.Method = \"POST\"");
writer.write("httpBindingEncoder, err := httpbinding.NewEncoder(request.URL.Path, "
+ "request.URL.RawQuery, request.Header)");
+ "request.URL.RawPath, request.URL.RawQuery, request.Header)");
writer.openBlock("if err != nil {", "}", () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
Expand Down
4 changes: 2 additions & 2 deletions encoding/httpbinding/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type Encoder struct {
// NewEncoder creates a new encoder from the passed in request. All query and
// header values will be added on top of the request's existing values. Overwriting
// duplicate values.
func NewEncoder(path, query string, headers http.Header) (*Encoder, error) {
func NewEncoder(path, rawPath, query string, headers http.Header) (*Encoder, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API break

Copy link
Contributor

@isaiahvita isaiahvita Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah this was my change from my raw not-yet-ready code, @syall lets remove this. and ill try to fix the bug in a diff way

parseQuery, err := url.ParseQuery(query)
if err != nil {
return nil, fmt.Errorf("failed to parse query string: %w", err)
}

e := &Encoder{
path: []byte(path),
rawPath: []byte(path),
rawPath: []byte(rawPath),
query: parseQuery,
header: headers.Clone(),
}
Expand Down
3 changes: 3 additions & 0 deletions encoding/httpbinding/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func newURIValue(path *[]byte, rawPath *[]byte, buffer *[]byte, key string) URIV
}

func (u URIValue) modifyURI(value string) (err error) {
if len(*u.rawPath) == 0 {
*u.rawPath = append([]byte(nil), *u.path...)
}
*u.path, *u.buffer, err = replacePathElement(*u.path, *u.buffer, u.key, value, false)
if err != nil {
return err
Expand Down
Loading