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

text/plain treated as json #223

Closed
dagardner-nv opened this issue Jul 27, 2023 · 3 comments
Closed

text/plain treated as json #223

dagardner-nv opened this issue Jul 27, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@dagardner-nv
Copy link

Describe the bug
Setting Content-Type: text/plain causes the response to be treated as if it were JSON.

To Reproduce
Steps to reproduce the behavior:

  1. Mock File Content
    GET.mock:
HTTP/1.1 200 OK
Content-Type: text/plain

line1
line2
line3

POST.mock

HTTP/1.1 200 OK
Content-Type: text/plain

OK
  1. Folder Structure
mocks/plain-text/
mocks/plain-text/POST.mock
mocks/plain-text/GET.mock
  1. Error Stack Trace
curl -v "http://localhost:8080/plain-text" 
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /plain-text HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.1.2
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: text/plain; charset=utf-8
< Content-Length: 15
< ETag: W/"f-MjRrWBZ2yhk5qhlHiP21s/LGDjo"
< Vary: Accept-Encoding
< Date: Thu, 27 Jul 2023 19:24:44 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
* Connection #0 to host localhost left intact
line1line2line3

Camouflage then logs:

2023-07-27 12:24:44 warn: Unexpected token l in JSON at position 0 

Expected behavior
Camouflage shouldn't attempt to parse output as JSON when content-type is text/plain.
New line characters should not be stripped from output.

Screenshots
n/a

Desktop (please complete the following information):

  • OS: Debian 11.7
  • Browser curl
  • Version 8.1.2

Additional context
camouflage.log

@dagardner-nv dagardner-nv added the bug Something isn't working label Jul 27, 2023
@dagardner-nv
Copy link
Author

I am able to work-around the issue using the file helper.

@shubhendumadhukar
Copy link
Contributor

@dagardner-nv

warn: Unexpected token l in JSON at position 0

Is a warning message that Camouflage throws since it expects responses to be json by default, however it doesn't affect your responses and the message can be ignored.

New lines being stripped out is a bug since we split the mock file contents with new line.

const fileContent = fileResponse.trim().split(newLine);

and then join them without the new line

responseBody = responseBody + line;

which should not be the case. I will provide a fix.

@shubhendumadhukar
Copy link
Contributor

🎉 This issue has been resolved in version 0.14.0 🎉

The release is available on:

npm package (@latest dist-tag)
GitHub release

rapids-bot bot pushed a commit to nv-morpheus/Morpheus that referenced this issue Sep 18, 2023
…1195)

* Adopt camouflage-server 0.15, previously we've been locked on v0.9 due to outstanding bugs introduced in versions 0.10 - 0.14.1 :
  - testinggospels/camouflage#203
  - testinggospels/camouflage#223  
  - testinggospels/camouflage#227
  - testinggospels/camouflage#229
* Includes unrelated fix to running CI locally
* Restrict mlflow to versions prior to 2.7

closes #967
Fixes #1192

## By Submitting this PR I confirm:
- I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md).
- When the PR is ready for review, new or existing tests cover these changes.
- When the PR is ready for review, the documentation is up to date with these changes.

Authors:
  - David Gardner (https://github.com/dagardner-nv)

Approvers:
  - Christopher Harris (https://github.com/cwharris)

URL: #1195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants