-
Notifications
You must be signed in to change notification settings - Fork 58
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 RequestPathPattern method to Typhon Request #169
Changes from 1 commit
84a107d
e9f9213
776b548
a976152
e4c8c20
7441813
fc0f840
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,7 +183,7 @@ func (r *Request) BodyBytes(consume bool) ([]byte, error) { | |
// Send round-trips the request via the default Client. It does not block, instead returning a ResponseFuture | ||
// representing the asynchronous operation to produce the response. It is equivalent to: | ||
// | ||
// r.SendVia(Client) | ||
// r.SendVia(Client) | ||
func (r Request) Send() *ResponseFuture { | ||
return Send(r) | ||
} | ||
|
@@ -213,6 +213,22 @@ func (r Request) ResponseWithCode(body interface{}, statusCode int) Response { | |
return rsp | ||
} | ||
|
||
// RouterEndpointPattern finds the router pattern that matches the request. This is only callable while the request | ||
// is being served. | ||
func (r Request) RouterEndpointPattern() string { | ||
if router := RouterForRequest(r); router != nil { | ||
if pathPattern := router.Pattern(r); pathPattern != "" { | ||
return pathPattern | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative implementation here would be to store the pattern used to serve the request in the context, as we do with the router currently. Then we don't need to look up the pattern separately (which could theoretically have changed if a new route is registered in the intervening time). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed it to store instead in e9f9213 👍 |
||
return "" | ||
} | ||
|
||
// RequestMethod returns the HTTP method of the request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not particularly keen on the name of this so any suggestions would be appreciated 🙇 . I'm also wondering if RouterEndpointMethod (which could be a "*") would be more beneficial here... |
||
func (r Request) RequestMethod() string { | ||
return r.Method | ||
} | ||
|
||
func (r Request) String() string { | ||
if r.URL == nil { | ||
return "Request(Unknown)" | ||
|
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.
RequestMethod()
feels intuitive and simple given we can't useMethod()
. 👍For this method,
RouterEntryPattern()
is probably the most correct, but wouldRequestPathPattern()
or evenRequestPattern()
be simpler and consistent?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.
Renamed to
RequestPathPattern()
in e9f9213. I suspect that RequestPattern by itself would require some background context to understand