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

RedirectPath #20

Merged
merged 43 commits into from
May 7, 2018
Merged

RedirectPath #20

merged 43 commits into from
May 7, 2018

Conversation

kkrull
Copy link
Owner

@kkrull kkrull commented May 2, 2018

Added a playground.RedirectRoute to handle /redirect

Test results

Starting Test System: slim using fitnesse.slim.SlimService.
. 17:06:48 R:0    W:0    I:0    E:0    SuiteSetUp       (HttpTestSuite.SuiteSetUp)      0.002 seconds
F 17:06:48 R:1    W:6    I:0    E:0    BasicAuth        (HttpTestSuite.ResponseTestSuite.BasicAuth)     0.000 seconds
F 17:06:48 R:0    W:4    I:0    E:1    CookieData       (HttpTestSuite.ResponseTestSuite.CookieData)    0.000 seconds
F 17:06:48 R:2    W:8    I:0    E:0    CreateReadUpdateDelete   (HttpTestSuite.ResponseTestSuite.CreateReadUpdateDelete)        0.001 seconds
. 17:06:48 R:6    W:0    I:0    E:0    DirectoryLinks   (HttpTestSuite.ResponseTestSuite.DirectoryLinks)        0.001 seconds
. 17:06:48 R:1    W:0    I:0    E:0    DirectoryListing (HttpTestSuite.ResponseTestSuite.DirectoryListing)      0.000 seconds
. 17:06:48 R:1    W:0    I:0    E:0    FileContents     (HttpTestSuite.ResponseTestSuite.FileContents)  0.000 seconds
. 17:06:48 R:3    W:0    I:0    E:0    FourEightTeen    (HttpTestSuite.ResponseTestSuite.FourEightTeen) 0.001 seconds
. 17:06:48 R:1    W:0    I:0    E:0    FourOhFour       (HttpTestSuite.ResponseTestSuite.FourOhFour)    0.001 seconds
. 17:06:48 R:3    W:0    I:0    E:0    ImageContent     (HttpTestSuite.ResponseTestSuite.ImageContent)  0.000 seconds
. 17:06:48 R:4    W:0    I:0    E:0    MediaTypes       (HttpTestSuite.ResponseTestSuite.MediaTypes)    0.001 seconds
. 17:06:48 R:6    W:0    I:0    E:0    MethodNotAllowed (HttpTestSuite.ResponseTestSuite.MethodNotAllowed)      0.000 seconds
. 17:06:48 R:2    W:0    I:0    E:0    ParameterDecode  (HttpTestSuite.ResponseTestSuite.ParameterDecode)       0.000 seconds
F 17:06:48 R:0    W:11   I:0    E:0    PartialContent   (HttpTestSuite.ResponseTestSuite.PartialContent)        0.000 seconds
F 17:06:48 R:4    W:2    I:0    E:0    PatchWithEtag    (HttpTestSuite.ResponseTestSuite.PatchWithEtag) 0.001 seconds
. 17:06:48 R:2    W:0    I:0    E:0    RedirectPath     (HttpTestSuite.ResponseTestSuite.RedirectPath)  0.001 seconds
. 17:06:48 R:1    W:0    I:0    E:0    SimpleGet        (HttpTestSuite.ResponseTestSuite.SimpleGet)     0.000 seconds
. 17:06:48 R:4    W:0    I:0    E:0    SimpleHead       (HttpTestSuite.ResponseTestSuite.SimpleHead)    0.001 seconds
. 17:06:48 R:6    W:0    I:0    E:0    SimpleOption     (HttpTestSuite.ResponseTestSuite.SimpleOption)  0.001 seconds
F 17:06:48 R:0    W:1    I:0    E:0    SimplePost       (HttpTestSuite.ResponseTestSuite.SimplePost)    0.000 seconds
F 17:06:48 R:0    W:1    I:0    E:0    SimplePut        (HttpTestSuite.ResponseTestSuite.SimplePut)     0.000 seconds
. 17:06:49 R:1    W:0    I:0    E:0    TimeToComplete   (HttpTestSuite.SimultaneousTestSuite.TimeToComplete)    0.002 seconds
. 17:06:49 R:0    W:0    I:0    E:0    SuiteTearDown    (HttpTestSuite.SuiteTearDown)   0.000 seconds
--------
23 Tests,       8 Failures      3.996 seconds.
0
Exit-Code: 7

@kkrull
Copy link
Owner Author

kkrull commented May 2, 2018

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
Copy link
Collaborator

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

Copy link
Owner Author

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 {
Copy link
Collaborator

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)?

Copy link
Owner Author

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",
Copy link
Collaborator

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

Copy link
Owner Author

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 consts

return &requestMessage{
method: method,
target: path,
path: path,
Copy link
Collaborator

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

Copy link
Owner Author

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})
Copy link
Collaborator

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?

Copy link
Owner Author

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:]
Copy link
Collaborator

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

Copy link
Owner Author

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)
Copy link
Collaborator

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?

Copy link
Owner Author

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.


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"))
Copy link
Collaborator

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

Copy link
Owner Author

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() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

Copy link
Owner Author

Choose a reason for hiding this comment

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

:)

}

func (*GoBackHomeResource) Get(client io.Writer, req http.RequestMessage) {
msg.WriteStatusLine(client, 302, "Found")
Copy link
Collaborator

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

Copy link
Owner Author

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.

@kkrull kkrull mentioned this pull request May 3, 2018
@kkrull kkrull merged commit a4a2b9a into master May 7, 2018
@kkrull kkrull deleted the redirect branch May 7, 2018 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants