Skip to content

Commit

Permalink
Provide proper error on GET request with body (#2138)
Browse files Browse the repository at this point in the history
* provide proper error

* enable body modification in GET/HEAD requests
  • Loading branch information
harunrst committed May 29, 2023
1 parent 5e6df1a commit 3869cf4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h3>
<!-- /ko -->
</details>

<!-- ko if: canHaveBody -->
<!-- ko if: canHaveBody || hasBody() -->
<details open class="details-styled">
<summary aria-label="body">
<h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export class OperationConsole {
this.responseStatusCode(null);
this.responseStatusText(null);
this.responseBody(null);
this.requestError(null);

const operation = await this.apiService.getOperation(selectedOperation.id);
const consoleOperation = new ConsoleOperation(selectedApi, operation);
Expand Down Expand Up @@ -378,6 +379,11 @@ export class OperationConsole {
* @param request HTTP request.
*/
public async sendFromBrowser(request: HttpRequest): Promise<HttpResponse> {

if ((request.method === HttpMethod.get || request.method === HttpMethod.head) && request.body) {
throw new RequestError("GET requests cannot have a body.");
}

const headersRequest: HeadersInit = {};
request.headers.forEach(header => headersRequest[header.name] = header.value);

Expand Down

0 comments on commit 3869cf4

Please sign in to comment.