-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Public HttpResponse class #28
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // | ||
| // Copyright 2012 Microsoft Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.WindowsAzure.ServiceLayer.Http | ||
| { | ||
| /// <summary> | ||
| /// Lists HTTP methods used by pipeline implementation. | ||
| /// </summary> | ||
| internal static class HttpMethod | ||
| { | ||
| internal const string Post = "POST"; | ||
| internal const string Get = "GET"; | ||
| internal const string Put = "PUT"; | ||
| internal const string Delete = "DELETE"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // | ||
| // Copyright 2012 Microsoft Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using NetHttpMethod = System.Net.Http.HttpMethod; | ||
| using NetHttpRequestMessage = System.Net.Http.HttpRequestMessage; | ||
|
|
||
| namespace Microsoft.WindowsAzure.ServiceLayer.Http | ||
| { | ||
| /// <summary> | ||
| /// Represents an HTTP request. | ||
| /// </summary> | ||
| public sealed class HttpRequest | ||
| { | ||
| private NetHttpMethod _method; // HTTP method verb (get/put/post, etc.) | ||
|
|
||
| /// <summary> | ||
| /// Gets the URI used for the HTTP request. | ||
| /// </summary> | ||
| public Uri Uri { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the HTTP method used for HTTP request. | ||
| /// </summary> | ||
| public string Method | ||
| { | ||
| get { return _method.ToString(); } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the headers. | ||
| /// </summary> | ||
| public IDictionary<string, string> Headers { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the content of the request. | ||
| /// </summary> | ||
| public HttpContent Content { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes the request. | ||
| /// </summary> | ||
| /// <param name="method">The request's HTTP method.</param> | ||
| /// <param name="uri">The request's URI.</param> | ||
| public HttpRequest(string method, Uri uri) | ||
| { | ||
| if (uri == null) | ||
| { | ||
| throw new ArgumentNullException("uri"); | ||
| } | ||
| if (method == null) | ||
| { | ||
| throw new ArgumentNullException("method"); | ||
| } | ||
|
|
||
| Uri = uri; | ||
| _method = new NetHttpMethod(method); | ||
| Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a .Net request and populates it with all data. | ||
| /// </summary> | ||
| /// <returns>.Net request.</returns> | ||
| internal NetHttpRequestMessage CreateNetRequest() | ||
| { | ||
| NetHttpRequestMessage request = new NetHttpRequestMessage(_method, Uri); | ||
|
|
||
| // Populate headers. | ||
| foreach (KeyValuePair<string, string> headerItem in Headers) | ||
| { | ||
| request.Headers.Add(headerItem.Key, headerItem.Value); | ||
| } | ||
|
|
||
| // Populate content. | ||
| if (Content != null) | ||
| { | ||
| Content.SubmitTo(request); | ||
| } | ||
| return 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. Should it have a new line inbetween the closing bracket and the return statement ? Usually R# advises for it and i kinda like it.
Author
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 don't have a strict preference for empy lines inside a body of a methods, however, I prefer to avoid having too many empty lines in the code because it blows up the document and reduces the amount of useful information that fits into a single screen. I don't think that an empty line here affects readability of the code in any way, so I'd prefer to keep it as is. |
||
| } | ||
| } | ||
| } | ||
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.
Maybe a better variable naming other than method ? seems confusing with _method ?
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 don't think it is that confusing. The scope of the "method" variable is limited to the constructor which is ~10 lines long; it's hard to get confused here.