-
Notifications
You must be signed in to change notification settings - Fork 0
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
RedirectPath #20
RedirectPath #20
Conversation
so it has access to query parameters, etc...
I recommend checking out the previous pull request, first. This pull request is only different by the last couple of commits. |
} | ||
|
||
type requestMessage struct { | ||
method string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been a pattern in some of your other work so far, but I wanted to 👍 the use of private attributes and getters where appropriate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm hoping to be able to hide a few more types within their respective packages, in the near future.
http/messages.go
Outdated
} | ||
} | ||
|
||
func NewOptionsMessage(target string) RequestMessage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for the naming mismatch between this and the other like methods (target
vs path
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - there are a few places I need to update for the other methods, since just about everything operates on the path portion of the target instead of the whole target.
This case does happen to be an edge case, where OPTIONS * HTTP/1.1
(note the lack of /
in the target) is a valid message: https://tools.ietf.org/html/rfc7230#section-5.3.4. That's why there's a different name for this one, although maybe some better naming could further clarify the intent.
http/messages.go
Outdated
|
||
func NewGetMessage(path string) RequestMessage { | ||
return &requestMessage{ | ||
method: "GET", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably extract these strings representing methods into some type of enum so that you don't have to type out the same string in various places/can get help from the compiler in the case of a fat finger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea - I'm extracting some const
s
return &requestMessage{ | ||
method: method, | ||
target: path, | ||
path: path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I need to be poking around deeper into the codebase, but it's not clear to me why these RequestMessage
objects have target
and path
attributes, given that they seem to always be the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that this is causing some confusion, even on my end. I think I got it pretty well cleaned up for GET requests, and I'm planning to address that during the next couple of stories (which deal with POST, PUT, and DELETE) requests.
} | ||
|
||
func (message *requestMessage) AddQueryFlag(name string) { | ||
message.queryParameters = append(message.queryParameters, QueryParameter{Name: name}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a QueryParameter
without a Value
is a QueryFlag
, perhaps it deserves its own object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea in general, to avoid a de-generate data structure. Let me get back to you on this one, as it would require some refactoring on the test side.
http/percent.go
Outdated
} | ||
|
||
func splitAfterHexCode(hexCodePlusUnencoded string) (hexCode string, unencoded string) { | ||
return hexCodePlusUnencoded[0:2], hexCodePlusUnencoded[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could use hexCodePlusUnencoded[:2]
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
http/percent.go
Outdated
} | ||
|
||
func decode(octetCharacters string) byte { | ||
asciiCode, _ := strconv.ParseInt(octetCharacters, 16, 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are 16 and 8 representing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll extract some constants to describe it better.
http/percent_test.go
Outdated
|
||
It("returns an error when % is followed by 1 character", func() { | ||
_, err := http.PercentDecode("abc%1") | ||
Expect(err).To(MatchError("% followed by fewer than 2 characters: abc%1")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might consider a custom error you could match against so that you don't need to repeat the exact string formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -91,7 +91,7 @@ var _ = Describe("InterruptFactory", func() { | |||
Expect(typedServer.Routes()).To(ContainElement(BeAssignableToTypeOf(capability.NewRoute()))) | |||
}) | |||
|
|||
XIt("has a playground route for parameter decoding", func() { | |||
It("has a playground route for parameter decoding", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
playground/redirect_route.go
Outdated
} | ||
|
||
func (*GoBackHomeResource) Get(client io.Writer, req http.RequestMessage) { | ||
msg.WriteStatusLine(client, 302, "Found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status codes and messages are also things I would consider wrapping in an enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I modified msg.WriteStatusLine
and to accept pre-defined msg.Status
objects. They're not guarded against mutation or re-assignment, but this seems to follow the pattern in the Go standard libraries nonetheless.
...and strip their names of magical powers
Added a
playground.RedirectRoute
to handle/redirect
Test results