USGS-WiM / StreamStatsServices

StreamStats REST Services
https://streamstats.usgs.gov/streamstatsservices
Other
1 stars 0 forks source link

Add to documentation the need for a 'withCredentials' header #36

Open marsmith opened 6 years ago

marsmith commented 6 years ago

For jquery/ajax:

xhrFields: {
          withCredentials: true
},
kjacobsen16 commented 4 years ago

This is the wording we've been using:

We are using a load balancer on production with sticky sessions enabled, so when using the production services there is an injected server-identifying cookie in the response header. If you are using the separate watershed/parameters endpoints, you need to ensure your requests are passing back the session cookies. This should be supported by all http clients, but in some cases needs to be activated. In our case all we needed to do was include the "withCredentials" header. Our service documentation page is outdated so this option has not been enabled, this could also be the cause of some of the issues. One way to verify is to look at the response headers of the watershed services to ensure they are coming from the same machine. ​ You can also look at the "usgswim-hostname" property of the watershed request response, and use that name for subsequent requests. The host name will be either "PRODWEBB" or "PRODWEBA". You can make direct requests using https://prodwebb.streamstats.usgs.gov/streamstatsservices or https://prodweba.streamstats.usgs.gov/streamstatsservices, etc., these should only be used after you've acquired your watershed the way you've been querying it.

amedenblik commented 2 years ago

Updated response:

StreamStats is hosted on two servers, and we use a load balancer to balance traffic between these two servers. When using StreamStatsServices, you will want to ensure that you use the same server for multiple service requests. There are several ways to do this:

  1. Add "withCredentials=true" to the header of your request. StreamStatsServices depends on cookies, and this header will make your browser include cookies in your request. a. For example, I make my request to https://streamstats.usgs.gov/streamstatsservices/watershed.geojson?rcode=VT&xlocation=-72.83726171529189&ylocation=44.70970662189513&crs=4326&includeparameters=true&includeflowtypes=false&includefeatures=true&simplify=true&withCredentials=true b. It returned workspace ID VT20211203175504031000 c. I make my second request to https://streamstats.usgs.gov/streamstatsservices/flowstatistics.json?rcode=VT&workspaceID=VT20211203175504031000&includeflowtypes=true&withCredentials=true
  2. Make direct requests to one specific server: prodweba.streamstats.usgs.gov or prodwebb.streamstats.usgs.gov a. For example, I make my request to https://prodweba.streamstats.usgs.gov/streamstatsservices/watershed.geojson?rcode=VT&xlocation=-72.83726171529189&ylocation=44.70970662189513&crs=4326&includeparameters=true&includeflowtypes=false&includefeatures=true&simplify=true b. It returned workspace ID VT20211203174022426000 c. I make my second request to https://prodweba.streamstats.usgs.gov/streamstatsservices/flowstatistics.json?rcode=VT&workspaceID=VT20211203174022426000&includeflowtypes=true
  3. If you do a request without using one of the above techniques, you can check the response headers for "usgswim-hostname". It will be "PRODWEBA" or "PRODWEBB". This will indicate which server you should use for any subsequent requests for which you want to use the same workspace ID.